Generate Weekly Schedule Calendar between two Date in ASP.Net MVC

sani.ss501
 
on May 24, 2021 04:26 AM
Sample_857624.zip
809 Views

WeeklySchedule calender in mvc c#

view is not show true

i want show all day but display day that is class

<div class="row" style="margin-right:15px;width:96%">
    <div class="col-lg-12">
        <table>
            <tr>
                <td style="width:150px;text-align:center"><h5>   @dayList[i].Name</h5><h5>   @dayList[i].DateTime.ConvertMiladiToShamsi("yyyy/MM/dd")</h5></td>
 
                @for (int j = 0; j < clockViewModel.Count; j++)
                {
 
                    @if (clockViewModel[j].DayId == dayList[i].Id)
                    {
                        <td style="text-align:right">
                            <table>
                                <tr style="text-align:right">
                                    <td style="text-align:right"><h6>درس :@dayList[i].TermCourse.Course.Title</h6></td>
                                </tr>
 
                                <tr style="text-align:right">
                                    <td style="text-align:right"><h6>شماره کلاس :@dayList[i].TermCourse.AcademyClassRoom.Title </h6></td>
                                    <td style="text-align:right"><h6>شماره کلاس :@dayList[i].TermCourse.AcademyClassRoom.Title </h6></td>
                                </tr>
                                <tr style="text-align:right">
                                    <td style="text-align:right">
                                        <h6>
                                            ساعت : @clockViewModel[j].StartTime -  @clockViewModel[j].FinishTime
                                        </h6>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    }
                }
 
            </tr>
        </table>
    </div>
</div>

 

public IActionResult PrintWeeky(string Id)
{
    var termCourse = _uw.BaseRepository<Entities.TermCourse>().FindByConditionAsync(x => x.Id == Id,null, c => c.Course, a => a.AcademyClassRoom, d => d.Days).Result.FirstOrDefault();
    var days = _uw.BaseRepository<Entities.Days>().FindByConditionAsync(x => x.TermCourseId == Id, null, c => c.Clocks).Result.OrderBy(x=>x.DateTime).ToList();
    ViewBag.DaysList = days;
    ViewBag.StartDate = termCourse.StartDate.Value.ToShortDateString();
    ViewBag.FinishDate = termCourse.FinishDate.Value.ToShortDateString();
    System.DateTime firstDate = new System.DateTime(termCourse.StartDate.Value.Year, termCourse.StartDate.Value.Month, termCourse.StartDate.Value.Day);
    System.DateTime secondDate = new System.DateTime(termCourse.FinishDate.Value.Year, termCourse.FinishDate.Value.Month, termCourse.FinishDate.Value.Day); 
 
    System.TimeSpan diff = secondDate.Subtract(firstDate);
    System.TimeSpan diff1 = secondDate - firstDate;
 
    String diff2 = (secondDate - firstDate).TotalDays.ToString();
 
    ViewBag.DaysCount = diff2;
   
    List<ClockViewModel> clockViewModel = new List<ClockViewModel>();
    if (termCourse != null)
    {
        ViewBag.termCourse = termCourse;
        ViewBag.TerCourseId = Id;
        ViewBag.Course = termCourse.Course.Title;
        ViewBag.CourseCode = termCourse.Course.Code;
        ViewBag.PracticalTimeHours = termCourse.Course.TotalPracticalTimeHours;
        ViewBag.TTheoryimeHours = termCourse.Course.TotalTTheoryimeHours;
    }
    for (int j = 0; j < days.Count; j++)
    {
        var resalt = _uw.ClockRepository.GetAllClockByDaysId(days[j].Id);
        for (int i = 0; i < days[j].Clocks.Count; i++)
        {
            ClockViewModel clock = new ClockViewModel();
            clock.DayId = days[j].Id;
            clock.DayName = days[j].Name;
            clock.StartTime = resalt[i].StartTime;
            clock.FinishTime = resalt[i].FinishTime;
            clockViewModel.Add(clock);
        }
    }
    ViewBag.clockViewModel = clockViewModel;
    return View();
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on May 29, 2021 12:33 AM

Hi sani.ss501,

Check this example. Now please take its reference and correct your code.

Controller

public class HomeController : Controller
{
    // GET: Home
    public ActionResult Index()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Index(string fromDate, string toDate)
    {
        DateTime startDate = Convert.ToDateTime(fromDate);
        DateTime endDate = Convert.ToDateTime(toDate);
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.Add("Sunday");
        dt.Columns.Add("Monday");
        dt.Columns.Add("Tuesday");
        dt.Columns.Add("Wednesday");
        dt.Columns.Add("Thursday");
        dt.Columns.Add("Friday");
        dt.Columns.Add("Saturday");
        System.Data.DataRow dr = dt.NewRow();

        for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
        {
            int i = (int)date.DayOfWeek;
            string day = date.DayOfWeek.ToString();
            dr[day] = date.ToString("yyyy/MM/dd");
            if (i == 6)
            {
                dt.Rows.Add(dr);
                dr = dt.NewRow();
            }
        }

        ViewBag.Data = dt;

        return View();
    }
}

View

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    @using (Html.BeginForm("Index", "Home", FormMethod.Post))
    {
        <span>Start:</span><input type="text" name="fromDate" /><br />
        <span>End:</span><input type="text" name="toDate" /><br />
        <input type="submit" value="Create" />
    }
    <hr />
    @if (ViewBag.Data != null)
    {
        <table>
            <thead>
                <tr>
                    <td>Su</td>
                    <td>Mo</td>
                    <td>Tu</td>
                    <td>We</td>
                    <td>Th</td>
                    <td>Fr</td>
                    <td>Sa</td>
                </tr>
            </thead>
            <tbody>
                @for (int i = 0; i < ViewBag.Data.Rows.Count; i++)
                {
                    <tr>
                        <td>@ViewBag.Data.Rows[i]["Sunday"]</td>
                        <td>@ViewBag.Data.Rows[i]["Monday"]</td>
                        <td>@ViewBag.Data.Rows[i]["Tuesday"]</td>
                        <td>@ViewBag.Data.Rows[i]["Wednesday"]</td>
                        <td>@ViewBag.Data.Rows[i]["Thursday"]</td>
                        <td>@ViewBag.Data.Rows[i]["Friday"]</td>
                        <td>@ViewBag.Data.Rows[i]["Saturday"]</td>
                    </tr>
                }
            </tbody>
        </table>
    }
</body>
</html>

Screenshot