public RenewRequestViewModel GetRenewRequest(int requestId)
        {
            if (requestId == 0)
            {
                return(new RenewRequestViewModel());
            }


            RenewRequestViewModel Request = context.RenewRequests.Where(r => r.Id == requestId).Select(rw => new RenewRequestViewModel
            {
                Id             = rw.Id,
                ApprovalStatus = rw.ApprovalStatus,
                ColumnName     = rw.ColumnName,
                EmpId          = rw.EmpId,
                CompanyId      = rw.CompanyId,
                NewValue       = rw.NewValue,
                NewValueId     = rw.NewValueId,
                OldValue       = rw.OldValue,
                OldValueId     = rw.OldValueId,
                RejectionRes   = rw.RejectionRes,
                RequestDate    = rw.RequestDate,
                CreatedUser    = rw.CreatedUser,
                CreatedTime    = rw.CreatedTime,
                Attachments    = HrContext.GetAttachments("RenewRequest", rw.Id)
            }).FirstOrDefault();

            return(Request);
        }
        public ActionResult Details(int id)
        {
            var    version = byte.Parse(Request.QueryString["Version"]);
            string RoleId  = Request.QueryString["RoleId"]?.ToString();

            ViewBag.colDropDown     = _hrUnitOfWork.PeopleRepository.GetEditColumn(CompanyId, "People", version, Language, RoleId).Select(g => new { id = g.ColumnName, name = g.Title });
            ViewBag.QualificationId = _hrUnitOfWork.QualificationRepository.GetAll().Select(a => new { id = a.Id, name = a.Name }).ToList();
            ViewBag.KafeelId        = _hrUnitOfWork.LookUpRepository.GetAllKafeels().Select(a => new { id = a.Id, name = a.Name }).ToList();
            ViewBag.Status          = _hrUnitOfWork.LookUpRepository.GetLookUpUserCodes("MaritalStat", Language).Select(a => new { id = a.CodeId, name = a.Title }).ToList();
            if (id == 0)
            {
                return(View(new RenewRequestViewModel()
                {
                    EmpId = EmpId, CompanyId = CompanyId
                }));
            }
            RenewRequestViewModel request = _hrUnitOfWork.PeopleRepository.GetRenewRequest(id);

            return(View(request));
        }
        public ActionResult Details(RenewRequestViewModel model, OptionsViewModel moreInfo)
        {
            List <Error> errors = new List <Error>();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    errors = _hrUnitOfWork.CompanyRepository.CheckForm(new CheckParm
                    {
                        CompanyId    = CompanyId,
                        ObjectName   = "RenewRequest",
                        TableName    = "RenewRequests",
                        Columns      = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))),
                        ParentColumn = "CompanyId",
                        Culture      = Language
                    });

                    if (errors.Count() > 0)
                    {
                        foreach (var e in errors)
                        {
                            foreach (var errorMsg in e.errors)
                            {
                                ModelState.AddModelError(errorMsg.field, errorMsg.message);
                            }
                        }
                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }
            }
            else
            {
                return(Json(Models.Utils.ParseFormErrors(ModelState)));
            }

            RenewRequest request = _hrUnitOfWork.PeopleRepository.Getrequest(model.Id);
            byte         version;

            byte.TryParse(Request.Form["version"], out version);
            string message = "OK";

            if (model.Id == 0)
            {
                request = new RenewRequest();
                //if (model.ColumnName== "QualificationId")
                //{
                //    model.OldValueId = int.Parse(model.OldValue);
                //    model.NewValueId = int.Parse(model.NewValue);
                //    model.NewValue= _hrUnitOfWork.QualificationRepository.GetAll().Where(qq => qq.Id == int.Parse(model.NewValue)).FirstOrDefault().Name;
                //    model.OldValue = _hrUnitOfWork.QualificationRepository.GetAll().Where(qq => qq.Id == int.Parse(model.OldValue)).FirstOrDefault().Name;
                //}
                //if (model.ColumnName == "MaritalStat")
                //{
                //    model.OldValueId = int.Parse(model.OldValue);
                //    model.NewValueId = int.Parse(model.NewValue);
                //    model.NewValue = _hrUnitOfWork.LookUpRepository.GetLookUpUserCodes("MaritalStat", Language).Where(qq => qq.CodeId == int.Parse(model.NewValue)).FirstOrDefault().Name;
                //    model.OldValue = _hrUnitOfWork.LookUpRepository.GetLookUpUserCodes("MaritalStat", Language).Where(qq => qq.CodeId == int.Parse(model.OldValue)).FirstOrDefault().Name;
                //}
                request.EmpId = EmpId;
                AutoMapperParm parms = new AutoMapperParm()
                {
                    Source = model, Destination = request, Version = version, ObjectName = "RenewRequest", Options = moreInfo, Transtype = TransType.Insert
                };
                AutoMapper(parms);

                request.ApprovalStatus = 2;
                request.CreatedUser    = UserName;
                request.CreatedTime    = DateTime.Now;
                _hrUnitOfWork.PeopleRepository.Add(request);
            }
            else
            {
                AutoMapperParm parms = new AutoMapperParm()
                {
                    Source = model, Destination = request, Version = version, ObjectName = "RenewRequest", Options = moreInfo, Transtype = TransType.Update
                };
                AutoMapper(parms);
                _hrUnitOfWork.PeopleRepository.Attach(request);
                _hrUnitOfWork.PeopleRepository.Entry(request).State = EntityState.Modified;
            }

            var Errors = SaveChanges(Language);

            if (Errors.Count > 0)
            {
                message = Errors.First().errors.First().message;
                return(Json(message));
            }
            if (message == "OK")
            {
                message += "," + ((new JavaScriptSerializer()).Serialize(request));
            }

            var js = Json(message);

            return(Json(message));
        }