Example #1
0
        public ActionResult Create(UserDTO model)
        {
            try
            {
                if(_userService.CheckAvailablity(model.Username))
                {
                    ModelState.AddModelError("", "Username already taken ");
                    bind();
                    return View();
                }
                if (model.UserTypeId==(int)UserType.TDR && !model.LocationId.HasValue)
                {
                    ModelState.AddModelError("", "Location is required for User type TDR ");
                    bind();
                    return View();
                }
                model.Id = Guid.NewGuid();
                model.Password = Md5Hash.GetMd5Hash("1234");
                _userService.Save(model);

                return RedirectToAction("Index");
            }
            catch (DomainValidationException ve)
            {
                ve.DomainValidationErrors(ModelState);
                bind();
                return View();
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                bind();
                return View();
            }
            return View();
        }
Example #2
0
 public BasicResponse Save(UserDTO dto)
 {
     var response = _userService.Save(dto);
     return response;
 }
Example #3
0
        public ActionResult Edit(UserDTO model)
        {
            try
            {

                if (model.UserTypeId == (int)UserType.TDR && !model.LocationId.HasValue)
                {
                    ModelState.AddModelError("", "Location is required for User type TDR ");
                    bind();
                    return View();
                }

                _userService.Save(model);

                return RedirectToAction("Index");
            }
            catch (DomainValidationException ve)
            {
                ve.DomainValidationErrors(ModelState);
                bind();
                return View();
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                bind();
                return View();
            }
            return View();
        }
Example #4
0
        public BasicResponse Save(UserDTO dto)
        {
            var response = new BasicResponse();
            try
            {
                var entity = new User
                {

                    Id = dto.Id,
                    Username = dto.Username,
                    IsActive = true,
                    Email = dto.Email,
                    Fullname = dto.Fullname,
                    Password = dto.Password,
                    PhoneNumber = dto.PhoneNumber,
                    UserType = (UserType)dto.UserTypeId,
                    ClientId = dto.ClientId,
                    LocationId = dto.LocationId,

                };
                _userRepository.Save(entity);
                response.Status = true;
                response.Info = "Success";

            }

            catch (Exception ex)
            {
                response.Status = false;
                if (ex is DomainValidationException)
                {
                    var dex = ex as DomainValidationException;
                    response.Info = dex.FormatException();
                }
                else
                {
                    response.Status = false;
                    response.Info = ex.Message;
                }

            }
            return response;
        }