Exemplo n.º 1
0
        public ActionResult Add(CalendarWorkingModel data, string submit)
        {
            var model = new CalendarWorking
            {
                ID = data.ID,
                Name_CalendarWorking = data.Name_CalendarWorking,
                Description          = data.Description,
                DateStart            = data.DateStart,
                DateEnd   = data.DateEnd,
                Address   = data.Address,
                WorkState = data.WorkState,
                Status    = data.Status,
                Files     = data.Files,
            };
            var userLogin     = (UserLogin)Session[Managing_Teacher_Work.Common.CommonConstants.USER_SESSION];
            var checkCalendar = db.CalendarWorking.Where(x => (model.ID != 0 ? x.ID != model.ID : true)).ToList()
                                .Where(x =>
                                       x.CalendarWorkingTeacher.Select(n => n.TeacherID).ToArray().Intersect(data.TeachersIDArray).Any() &&
                                       x.DateStart.Date <= model.DateEnd.Date &&
                                       x.DateEnd.Date >= model.DateStart.Date);
            var calendarWorkingTeachers = new List <CalendarWorkingTeacher>();

            if (checkCalendar.Count() > 0)
            {
                SetAlert("Giảng viên đã có lịch công tác trong thời gian này! :D", "error");
                return(RedirectToAction("Index"));
            }
            if (submit == "Thêm")
            {
                isThemMoi = true;
                if (model != null)
                {
                    model.Name_CalendarWorking = model.Name_CalendarWorking.ToString();

                    model.Description = model.Description.ToString();
                    model.DateStart   = model.DateStart;
                    model.DateEnd     = model.DateEnd;
                    model.Address     = model.Address != null ? model.Address : "";
                    model.WorkState   = model.WorkState;
                    model.Status      = model.Status;
                    model.CreatedDate = model.CreatedDate.GetValueOrDefault(System.DateTime.Now);

                    foreach (var item in data.TeachersIDArray)
                    {
                        calendarWorkingTeachers.Add(new CalendarWorkingTeacher
                        {
                            TeacherID         = item,
                            CalendarWorkingID = model.ID,
                        });
                    }
                    model.CalendarWorkingTeacher = calendarWorkingTeachers;
                    db.CalendarWorking.Add(model);
                    db.CalendarWorkingTeacher.AddRange(calendarWorkingTeachers);
                    db.SaveChanges();
                    model = null;
                }
                SetAlert("Thêm thông tin thành công! :D", "success");
                return(RedirectToAction("Index"));
            }
            else if (submit == "Cập Nhật")
            {
                isThemMoi = false;
                if (model != null)
                {
                    db.CalendarWorkingTeacher.RemoveRange(db.CalendarWorkingTeacher.Where(x => x.CalendarWorkingID == model.ID));
                    db.SaveChanges();
                    var list = db.CalendarWorking.SingleOrDefault(x => x.ID == model.ID);
                    list.Name_CalendarWorking = model.Name_CalendarWorking;
                    list.Description          = model.Description;
                    list.DateStart            = model.DateStart;
                    list.DateEnd      = model.DateEnd;
                    list.Address      = model.Address;
                    list.WorkState    = model.WorkState;
                    list.Status       = model.Status;
                    list.ModifiedDate = model.CreatedDate.GetValueOrDefault(System.DateTime.Now);


                    foreach (var item in data.TeachersIDArray)
                    {
                        calendarWorkingTeachers.Add(new CalendarWorkingTeacher
                        {
                            TeacherID         = item,
                            CalendarWorkingID = model.ID,
                        });
                    }
                    model.CalendarWorkingTeacher = calendarWorkingTeachers;
                    db.CalendarWorkingTeacher.AddRange(calendarWorkingTeachers);
                    db.SaveChanges();
                    model = null;
                }
                SetAlert("Cập nhật thông tin thành công! :D", "success");
                return(RedirectToAction("Index"));
            }
            else if (submit == "Tìm")
            {
                if (!string.IsNullOrEmpty(model.Name_CalendarWorking))
                {
                    List <CalendarWorking> list = GetData().Where(s => s.Name_CalendarWorking.Contains(model.Name_CalendarWorking)).ToList();
                    return(View("Index", list));
                }
                else
                {
                    List <CalendarWorking> list = GetData();
                    return(View("Index", list));
                }
            }
            else
            {
                List <CalendarWorking> list = GetData().OrderBy(s => s.Name_CalendarWorking).ToList();
                return(View("Index", list));
            }
        }
Exemplo n.º 2
0
 public Task <bool> CreateCalendarWorkingAsync(CalendarWorking model)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 3
0
        public ActionResult Add(CalendarWorking model, string submit)
        {
            if (submit == "Thêm")
            {
                isThemMoi = true;
                if (model != null)
                {
                    model.Name_CalendarWorking = model.Name_CalendarWorking.ToString();

                    model.Description    = model.Description.ToString();
                    model.DateStart      = model.DateStart;
                    model.DateEnd        = model.DateEnd;
                    model.Address        = model.Address != null ? model.Address : "";
                    model.TeacherID      = model.TeacherID;
                    model.WorkID         = model.WorkID;
                    model.TypeCalendarID = model.TypeCalendarID;
                    model.WorkState      = model.WorkState;
                    model.Status         = model.Status;
                    model.CreatedDate    = model.CreatedDate.GetValueOrDefault(System.DateTime.Now);

                    db.CalendarWorking.Add(model);
                    db.SaveChanges();
                    model = null;
                }
                SetAlert("Thêm thông tin thành công! :D", "success");
                return(RedirectToAction("Index"));
            }
            else if (submit == "Cập Nhật")
            {
                isThemMoi = false;
                if (model != null)
                {
                    var list = db.CalendarWorking.SingleOrDefault(x => x.ID == model.ID);
                    list.Name_CalendarWorking = model.Name_CalendarWorking;
                    list.Description          = model.Description;
                    list.DateStart            = model.DateStart;
                    list.DateEnd        = model.DateEnd;
                    list.Address        = model.Address.ToString();
                    list.TeacherID      = model.TeacherID;
                    list.WorkID         = model.WorkID;
                    list.TypeCalendarID = model.TypeCalendarID;
                    list.WorkState      = model.WorkState;
                    list.Status         = model.Status;
                    list.ModifiedDate   = model.CreatedDate.GetValueOrDefault(System.DateTime.Now);
                    db.SaveChanges();
                    model = null;
                }
                SetAlert("Cập nhật thông tin thành công! :D", "success");
                return(RedirectToAction("Index"));
            }
            else if (submit == "Tìm")
            {
                if (!string.IsNullOrEmpty(model.Name_CalendarWorking))
                {
                    List <CalendarWorking> list = GetData().Where(s => s.Name_CalendarWorking.Contains(model.Name_CalendarWorking)).ToList();
                    return(View("Index", list));
                }
                else
                {
                    List <CalendarWorking> list = GetData();
                    return(View("Index", list));
                }
            }
            else
            {
                List <CalendarWorking> list = GetData().OrderBy(s => s.Name_CalendarWorking).ToList();
                return(View("Index", list));
            }
        }