Ejemplo n.º 1
0
        public ActionResult Edit(DayOffViewModel model)
        {
            if (ModelState.IsValid)
            {
                var urlRefer = Request["UrlReferrer"];
                var DayOff   = DayOffRepository.GetDayOffById(model.Id);
                if (Request["Submit"] == "Save")
                {
                    AutoMapper.Mapper.Map(model, DayOff);
                    DayOff.ModifiedUserId = WebSecurity.CurrentUserId;
                    DayOff.ModifiedDate   = DateTime.Now;
                    var dates = new List <DateTime>();
                    for (DateTime dt = model.DayStart.Value; dt <= model.DayEnd.Value; dt = dt.AddDays(1))
                    {
                        dates.Add(dt);
                    }
                    DayOff.Quantity = dates.Count();
                    var typeDayOff = typeDayOffRepository.GetSymbolTimekeepingById(model.TypeDayOffId.Value);

                    var dayoff         = DayOffRepository.GetAllDayOff().AsEnumerable().Where(x => x.TypeDayOffId == model.TypeDayOffId && x.DayStart.Value.ToString("yyyy") == model.DayStart.Value.ToString("yyyy") && x.StaffId == model.StaffId).ToList();
                    int QuantityDayOff = 0;
                    if (dayoff.Count() > 0)
                    {
                        foreach (var item in dayoff)
                        {
                            if (item.Id != model.Id)
                            {
                                QuantityDayOff += item.Quantity.Value;
                            }
                        }
                    }
                    DayOff.QuantityNotUsed = typeDayOff.Quantity - (QuantityDayOff + DayOff.Quantity);
                    if (DayOff.QuantityNotUsed < 0)
                    {
                        TempData[Globals.FailedMessageKey] = "Số ngày nghỉ" + model.NameSymbol + " còn lại của bạn không đủ";
                        if (Request["IsPopup"] == "true" || Request["IsPopup"] == "True")
                        {
                            ViewBag.closePopup = "true";
                        }
                        ViewBag.urlRefer = urlRefer;
                        return(View(model));
                    }
                    else
                    {
                        DayOffRepository.UpdateDayOff(DayOff);
                        if (Request["IsPopup"] == "true" || Request["IsPopup"] == "True")
                        {
                            TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess;
                            ViewBag.closePopup = "true";
                            ViewBag.urlRefer   = urlRefer;
                            return(View(model));
                        }
                    }
                }
                return(Redirect(urlRefer));
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult AddDotGQCDBHXHDetail(int?DotGQCDBHXHId, int?DayOffId, int?StaffId)
        {
            var DotGQCDBHXHDetail = new DotGQCDBHXHDetail();

            DotGQCDBHXHDetail.IsDeleted      = false;
            DotGQCDBHXHDetail.CreatedUserId  = WebSecurity.CurrentUserId;
            DotGQCDBHXHDetail.ModifiedUserId = WebSecurity.CurrentUserId;
            DotGQCDBHXHDetail.AssignedUserId = WebSecurity.CurrentUserId;
            DotGQCDBHXHDetail.CreatedDate    = DateTime.Now;
            DotGQCDBHXHDetail.ModifiedDate   = DateTime.Now;
            DotGQCDBHXHDetail.DotGQCDBHXHId  = DotGQCDBHXHId;
            DotGQCDBHXHDetail.DayOffId       = DayOffId;
            DotGQCDBHXHDetail.StaffId        = StaffId;
            var dayoff = DayOffRepository.GetDayOffById(DayOffId.Value);

            if (dayoff != null)
            {
                DotGQCDBHXHDetail.DayEnd   = dayoff.DayEnd;
                DotGQCDBHXHDetail.DayStart = dayoff.DayStart;
                DotGQCDBHXHDetail.Quantity = dayoff.Quantity;
                var SocietyCode = StaffSocialInsuranceRepository.GetStaffSocialInsuranceByStaffId(StaffId.Value);
                if (SocietyCode != null)
                {
                    DotGQCDBHXHDetail.SocietyCode = SocietyCode.SocietyCode;
                }
            }
            DotGQCDBHXHDetailRepository.InsertDotGQCDBHXHDetail(DotGQCDBHXHDetail);

            return(Content("success"));
        }