示例#1
0
        public ItemRequestViewModel SavePersonalItemRequest(ItemRequestViewModel model)
        {
            exceptionService.Execute((m) =>
            {
                model.DocumentSetupId = (int)eDocumentSetup.ItemRequest;

                if (model.Details.Count == 0)
                {
                    model.Errors.Add(new ValidationResult("Please enter detail.", new string[] { "" }));
                }

                if (model.Errors.Any())
                {
                    return;
                }

                if (!model.Validate())
                {
                    return;
                }

                model.Date = model.DateBS.GetDate();

                var entity = new ItemRequest();

                if (model.Id > 0)
                {
                    entity         = itemRequestRepository.GetById(model.Id);
                    entity.Date    = model.Date;
                    entity.Remarks = model.Remarks;
                    itemRequestDetailRepository.DeleteRange(entity.ItemRequestDetails);
                }
                else
                {
                    entity = AutomapperConfig.Mapper.Map <ItemRequest>(model);
                    itemRequestRepository.Insert(entity);
                }

                foreach (var item in model.Details)
                {
                    var detail           = AutomapperConfig.Mapper.Map <ItemRequestDetail>(item);
                    detail.ItemRequestId = entity.Id;
                    itemRequestDetailRepository.Insert(detail);
                }

                if (model.Id == 0)
                {
                    model.Message = localizationService.GetLocalizedText("Message.DataSavedSuccessfully", "Data saved successfully.");
                }
                else
                {
                    model.Message = localizationService.GetLocalizedText("Message.DataSavedSuccessfully", "Save changes successfully.");
                }
            }, model);
            return(model);
        }
示例#2
0
        public ItemRequestViewModel SaveItemRequest(ItemRequestViewModel model)
        {
            exceptionService.Execute((m) =>
            {
                model.DocumentSetupId = (int)eDocumentSetup.ItemRequest;

                if (model.Details.Count == 0)
                {
                    model.Errors.Add(new ValidationResult("Please enter detail.", new string[] { "" }));
                }

                if (model.Errors.Any())
                {
                    return;
                }

                if (!model.Validate())
                {
                    return;
                }

                model.Date = model.DateBS.GetDate();

                var entity = new ItemRequest();

                if (model.Id > 0)
                {
                    entity         = itemRequestRepository.GetById(model.Id);
                    entity.Date    = model.Date;
                    entity.Remarks = model.Remarks;
                    itemRequestDetailRepository.DeleteRange(entity.ItemRequestDetails);
                }
                else
                {
                    entity = AutomapperConfig.Mapper.Map <ItemRequest>(model);
                    entity.ApplicationStatus = (int)eApplicationStatus.Applied;
                    itemRequestRepository.Insert(entity);
                }

                foreach (var item in model.Details)
                {
                    var detail           = AutomapperConfig.Mapper.Map <ItemRequestDetail>(item);
                    detail.ItemRequestId = entity.Id;
                    itemRequestDetailRepository.Insert(detail);
                }

                if (model.Id == 0)
                {
                    model.Message = localizationService.GetLocalizedText("Message.DataSavedSuccessfully", "Data saved successfully.");
                }
                else
                {
                    model.Message = localizationService.GetLocalizedText("Message.DataSavedSuccessfully", "Save changes successfully.");
                }

                var receiver = employeeRepository.GetById(model.RequestedEmployeeId);
                if (receiver != null)
                {
                    //intialize workflow
                    var workflowResponse = workflowService.InitiliazeWorkflow(NTAEnum.eWorkFlowType.ItemRequest, entity.Id, model.EmployeeId, model.RequestedEmployeeId, new Dictionary <string, string>());
                    if (workflowResponse.Status != ViewModels.BackOffice.Workflow.eWorkflowReponseStatus.Success)
                    {
                        model.Errors.Add(new ValidationResult("An error has occured. " + workflowResponse.Message));
                        var itemReqDetail = itemRequestDetailRepository.Table.Where(x => x.ItemRequestId == entity.Id);
                        itemRequestDetailRepository.DeleteRange(itemReqDetail);
                        itemRequestRepository.Delete(entity.Id);
                        return;
                    }
                }
            }, model);
            return(model);
        }