예제 #1
0
        public async Task <object> PutUser([FromBody] User model)
        {
            // 这里使用事务处理
            var data = new MessageModel <string>();

            try
            {
                _unitOfWork.BeginTran();

                var roleList = await _roleSvc.GetDataByids(model.RoleIds);

                model.RoleInfoList = _mapper.Map <IList <Role>, IList <InfoRole> >(roleList);

                if (model != null && model.Id > 0)
                {
                    model.ModifyTime = DateTime.Now;
                    data.Success     = await _userSvc.Update(model);

                    _unitOfWork.CommitTran();

                    if (data.Success)
                    {
                        data.Message  = "更新成功";
                        data.Response = model?.Id.ToString();
                    }
                }
            }
            catch (Exception)
            {
                _unitOfWork.RollbackTran();
            }

            return(data);
        }
예제 #2
0
        //[ValidateAntiForgeryToken]
        public ActionResult Register(Models.UserViewModel uvModel, HttpPostedFileBase file)
        {
            string folderName = string.Empty;

            //if (file != null)
            //{
            //    if (file.ContentLength > 0)
            //    {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                string keyName = Request.Files.Keys[i];
                folderName = _configSvc.GetEmployeeImagesFolder();
                SaveImageFiles(folderName, Request.Files[i].FileName, uvModel.Employee.StaffEmployeeId);
            }
            //    }
            //}

            SessionDTO sessionRet = _sessionSvc.GetUserSession();

            uvModel.CreatedBy = sessionRet;

            DateTime dtValidator = new DateTime();

            if (DateTime.TryParse(uvModel.DOBString, out dtValidator))
            {
                uvModel.DOB = dtValidator;
            }

            if (DateTime.TryParse(uvModel.DOJString, out dtValidator))
            {
                if (uvModel.Employee == null)
                {
                    uvModel.Employee = new EmployeeDetailsDTO();
                }
                uvModel.Employee.DateOfJoining = dtValidator;
            }

            if (string.Equals(uvModel.MODE, "EDIT", StringComparison.OrdinalIgnoreCase))
            {
                //Call update

                StatusDTO <UserMasterDTO> status = _userSvc.Update(uvModel);

                if (status.IsSuccess)
                {
                    if (uvModel.UserEntitlementList != null && uvModel.UserEntitlementList.Count > 0)
                    {
                        for (int i = 0; i < uvModel.UserEntitlementList.Count; i++)
                        {
                            if (uvModel.UserEntitlementList[i].RowId > 0)
                            {
                                _userSvc.UpdateUserEntitlement(uvModel.UserEntitlementList[i]);
                            }
                            else
                            {
                                uvModel.UserEntitlementList[i].UserDetails = new UserMasterDTO();
                                uvModel.UserEntitlementList[i].UserDetails.UserMasterId = uvModel.UserMasterId;
                                _userSvc.InsertUserEntitlement(uvModel.UserEntitlementList[i]);
                            }
                        }
                    }

                    if (uvModel.FacultyCourseList != null && uvModel.FacultyCourseList.Count > 0)
                    {
                        for (int i = 0; i < uvModel.FacultyCourseList.Count; i++)
                        {
                            if (uvModel.FacultyCourseList[i].FacultyCourseMapId > 0)
                            {
                                _userSvc.UpdateFacultyCourseMap(uvModel.FacultyCourseList[i]);
                            }
                            else
                            {
                                uvModel.FacultyCourseList[i].Employee            = new EmployeeDetailsDTO();
                                uvModel.FacultyCourseList[i].Employee.EmployeeId = uvModel.hdnEmployeeId;
                                _userSvc.InsertFacultyCourse(uvModel.FacultyCourseList[i]);
                            }
                        }
                    }
                }

                return(RedirectToAction("Search", "User", new { area = "User" }));
            }
            else
            {
                //Call insert

                string pass = encrypt.encryption(uvModel.Password);
                uvModel.Password = pass;


                uvModel.CreatedBy = sessionRet;
                StatusDTO <UserMasterDTO> status = _userSvc.Insert(uvModel);

                if (status.IsSuccess)
                {
                    if (uvModel.UserEntitlementList != null && uvModel.UserEntitlementList.Count > 0)
                    {
                        for (int i = 0; i < uvModel.UserEntitlementList.Count; i++)
                        {
                            uvModel.UserEntitlementList[i].UserDetails = new UserMasterDTO();
                            uvModel.UserEntitlementList[i].UserDetails.UserMasterId = status.ReturnObj.UserMasterId;
                            _userSvc.InsertUserEntitlement(uvModel.UserEntitlementList[i]);
                        }
                    }

                    if (uvModel.FacultyCourseList != null && uvModel.FacultyCourseList.Count > 0)
                    {
                        for (int i = 0; i < uvModel.FacultyCourseList.Count; i++)
                        {
                            uvModel.FacultyCourseList[i].Employee            = new EmployeeDetailsDTO();
                            uvModel.FacultyCourseList[i].Employee.EmployeeId = status.ReturnObj.Employee.EmployeeId;
                            _userSvc.InsertFacultyCourse(uvModel.FacultyCourseList[i]);
                        }
                    }
                }
                uvModel.GenderList      = _uiddlRepo.getGenderDropDown();
                uvModel.LocationList    = _uiddlRepo.getLocationDropDown();
                uvModel.RoleList        = _uiddlRepo.getRoleDropDown();
                uvModel.DepartmentList  = _uiddlRepo.getDepartmentDropDown();
                uvModel.DesignationList = _uiddlRepo.getDesignationDropDown();

                //return View(uvModel);
                return(RedirectToAction("Search", "User", new { area = "User" }));
            }
        }