示例#1
0
        public IHttpActionResult GetTrainEventObj(int id = 0)
        {
            var    CourseId = _hrUnitOfWork.TrainingRepository.GetTrainCourse(User.Identity.GetLanguage(), User.Identity.GetDefaultCompany()).Select(p => new { id = p.Id, name = p.LocalName });
            var    CenterId = _hrUnitOfWork.LookUpRepository.GetAllHospitals(6).Select(a => new { id = a.Id, name = a.Name });
            var    CurrCode = _hrUnitOfWork.LookUpRepository.GetCurrencyCode();
            var    PersonId = _hrUnitOfWork.PeopleRepository.GetActiveEmployees(User.Identity.GetDefaultCompany(), User.Identity.GetLanguage());
            string Curr     = _PersonSetup.LocalCurrCode;
            float  MidRat   = _hrUnitOfWork.LookUpRepository.GetCurrency().Where(a => a.Code == Curr).Select(a => a.MidRate).FirstOrDefault();
            TrainEventFormViewModel TrainObj;

            if (id == 0)
            {
                TrainObj = new TrainEventFormViewModel();
            }
            else
            {
                TrainObj = _hrUnitOfWork.TrainingRepository.ReadTrainEvent(id);
            }
            return(Ok(new { TrainObj = TrainObj, CourseIdLst = CourseId, CurrCodeLst = CurrCode, CenterId = CenterId, PersonId = PersonId, Curr = Curr, MidRat = MidRat }));
        }
示例#2
0
        public ActionResult Details(TrainEventFormViewModel model, OptionsViewModel moreInfo)
        {
            List <Error> errors = new List <Error>();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    errors = _hrUnitOfWork.SiteRepository.CheckForm(new CheckParm
                    {
                        CompanyId    = CompanyId,
                        ObjectName   = "TrainEvents",
                        TableName    = "TrainEvents",
                        ParentColumn = "CourseId",
                        Columns      = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))),
                        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)));
                    }
                }

                TrainEvent     record;
                PeopleTraining PeopleTrainObj = new PeopleTraining();
                var            message        = "OK";

                //insert
                if (model.Id == 0)
                {
                    record = new TrainEvent();
                    AutoMapper(new Models.AutoMapperParm
                    {
                        Destination = record,
                        Source      = model,
                        ObjectName  = "TrainEvents",
                        Options     = moreInfo,
                        Transtype   = TransType.Insert
                    });

                    record.CreatedUser = UserName;
                    record.CreatedTime = DateTime.Now;

                    _hrUnitOfWork.TrainingRepository.Add(record);
                }

                //booking
                else if (model.book)
                {
                    record = _hrUnitOfWork.Repository <TrainEvent>().FirstOrDefault(a => a.Id == model.Id);
                    PeopleTrainObj.CreatedUser    = UserName;
                    PeopleTrainObj.CreatedTime    = DateTime.Now;
                    PeopleTrainObj.CompanyId      = CompanyId;
                    PeopleTrainObj.ApprovalStatus = 2;
                    PeopleTrainObj.RequestDate    = DateTime.Now;
                    PeopleTrainObj.EmpId          = (model.PersonId != null ? model.PersonId.Value: User.Identity.GetEmpId());
                    PeopleTrainObj.CourseEDate    = model.TrainEndDate;
                    PeopleTrainObj.CourseSDate    = model.TrainStartDate;
                    PeopleTrainObj.EventId        = record.Id;
                    PeopleTrainObj.CompanyId      = CompanyId;
                    PeopleTrainObj.Cost           = record.Cost;
                    PeopleTrainObj.Curr           = record.Curr;
                    PeopleTrainObj.CurrRate       = record.CurrRate;
                    PeopleTrainObj.Notes          = record.Notes;
                    PeopleTrainObj.CourseId       = record.CourseId;
                    PeopleTrainObj.Adwarding      = record.Adwarding;

                    _hrUnitOfWork.TrainingRepository.Add(PeopleTrainObj);
                }

                //update
                else
                {
                    record = _hrUnitOfWork.Repository <TrainEvent>().FirstOrDefault(a => a.Id == model.Id);
                    AutoMapper(new Models.AutoMapperParm
                    {
                        Destination = record,
                        Source      = model,
                        ObjectName  = "TrainEvents",
                        Options     = moreInfo,
                        Transtype   = TransType.Update
                    });

                    record.ModifiedTime = DateTime.Now;
                    record.ModifiedUser = UserName;

                    _hrUnitOfWork.TrainingRepository.Attach(record);
                    _hrUnitOfWork.TrainingRepository.Entry(record).State = EntityState.Modified;
                }
                errors = SaveChanges(Language);
                if (errors.Count > 0)
                {
                    message = errors.First().errors.First().message;
                }
                if (model.book)
                {
                    WfViewModel wf = new WfViewModel()
                    {
                        Source         = "Training",
                        SourceId       = CompanyId,
                        DocumentId     = PeopleTrainObj.Id,
                        RequesterEmpId = PeopleTrainObj.EmpId,
                        ApprovalStatus = 2,
                        CreatedUser    = UserName,
                    };
                    var wfTrans = _hrUnitOfWork.ComplaintRepository.AddWorkFlow(wf, Language);
                    if (wfTrans == null && wf.WorkFlowStatus != "Success")
                    {
                        PeopleTrainObj.ApprovalStatus = 2;
                        message = wf.WorkFlowStatus;
                    }
                    else if (wfTrans != null)
                    {
                        _hrUnitOfWork.LeaveRepository.Add(wfTrans);
                    }
                    errors = SaveChanges(Language);
                }

                return(Json(message));
            }
            return(Json(Models.Utils.ParseFormErrors(ModelState)));
        }
示例#3
0
        public IHttpActionResult SaveTrainEvent(TrainEventFormViewModel model)
        {
            List <Model.ViewModel.Error> errors = new List <Model.ViewModel.Error>();

            if (!ModelState.IsValid)
            {
                return(Json(Utils.ParseFormError(ModelState)));
            }

            string         message        = "Ok";
            PeopleTraining PeopleTrainObj = new PeopleTraining();

            TrainEvent record = _hrUnitOfWork.Repository <TrainEvent>().FirstOrDefault(a => a.Id == model.Id);

            if (model.PersonId != null)
            {
                PeopleTrainObj.EmpId = model.PersonId.GetValueOrDefault();
            }
            else
            {
                PeopleTrainObj.EmpId = 1042;
            }
            PeopleTrainObj.EmpId          = User.Identity.GetEmpId();
            PeopleTrainObj.CreatedUser    = User.Identity.Name;
            PeopleTrainObj.CreatedTime    = DateTime.Now;
            PeopleTrainObj.CompanyId      = User.Identity.GetDefaultCompany();
            PeopleTrainObj.ApprovalStatus = 2;
            PeopleTrainObj.RequestDate    = DateTime.Now;
            PeopleTrainObj.CourseEDate    = model.TrainEndDate;
            PeopleTrainObj.CourseSDate    = model.TrainStartDate;
            PeopleTrainObj.EventId        = record.Id;
            PeopleTrainObj.CompanyId      = User.Identity.GetDefaultCompany();
            PeopleTrainObj.Cost           = record.Cost;
            PeopleTrainObj.Curr           = record.Curr;
            PeopleTrainObj.CurrRate       = record.CurrRate;
            PeopleTrainObj.Notes          = record.Notes;
            PeopleTrainObj.CourseId       = record.CourseId;
            PeopleTrainObj.Adwarding      = record.Adwarding;
            _hrUnitOfWork.TrainingRepository.Add(PeopleTrainObj);

            errors = SaveChanges(User.Identity.GetLanguage());
            if (errors.Count > 0)
            {
                message = errors.First().errors.First().message;
            }
            if (model.book)
            {
                WfViewModel wf = new WfViewModel()
                {
                    Source         = "Training",
                    SourceId       = User.Identity.GetDefaultCompany(),
                    DocumentId     = PeopleTrainObj.Id,
                    RequesterEmpId = PeopleTrainObj.EmpId,
                    ApprovalStatus = 2,
                    CreatedUser    = User.Identity.Name,
                };
                var wfTrans = _hrUnitOfWork.ComplaintRepository.AddWorkFlow(wf, User.Identity.GetLanguage());
                if (wfTrans == null && wf.WorkFlowStatus != "Success")
                {
                    PeopleTrainObj.ApprovalStatus = 2;
                    message = wf.WorkFlowStatus;
                }
                else if (wfTrans != null)
                {
                    _hrUnitOfWork.LeaveRepository.Add(wfTrans);
                }
                errors = SaveChanges(User.Identity.GetLanguage());
            }
            return(Ok(message));
        }