public ActionResult UpdateUserMaintenance(string key, string values)
        {
            //Get Data and Merge
            UserMaintenanceViewModel UserUpdate = new UserMaintenanceViewModel();

            //this.SecurityService.GetUserMaintenance(new UserCriteria() { UserID = key}).FirstOrDefault().ToModel();
            JsonConvert.PopulateObject(values, UserUpdate);
            ValidateModel(UserUpdate);
            if (!TryValidateModel(UserUpdate))                           // Validating the updated item
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserUpdate.Password    = CommonUtils.Encrypt(UserUpdate.Password);
            UserUpdate.UpdatedBy   = UserDetail.UserID;
            UserUpdate.UpdatedDate = CurrentDateTime;
            this.SecurityService.UpdateUser(UserUpdate.ToEntity(), UserUpdate.CompanyCodeList, UserUpdate.PlantCodeList);

            return(new HttpStatusCodeResult(HttpStatusCode.Created));
        }
        public ActionResult InsertUserMaintenance(string values)
        {
            UserMaintenanceViewModel userInsert = new UserMaintenanceViewModel();

            JsonConvert.PopulateObject(values, userInsert);

            //check duplicate
            //UserMaintenanceViewModel userDup = this.SecurityService.GetUserMaintenance(new UserCriteria() { UserID = userInsert.UserID }).FirstOrDefault().ToModel();
            //if (userDup != null)
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "User ID is Duplicate");
            userInsert.Password    = CommonUtils.Encrypt(userInsert.Password);
            userInsert.CreatedBy   = userInsert.UpdatedBy = UserDetail.UserID;
            userInsert.CreatedDate = userInsert.UpdatedDate = CurrentDateTime;
            ValidateModel(userInsert);
            if (!TryValidateModel(userInsert))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            this.SecurityService.InsertUser(userInsert.ToEntity(), userInsert.CompanyCodeList, userInsert.PlantCodeList);
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        public HttpResponseMessage UpateProfile(PersonalinfoBEL profileInfo)//, HttpPostedFileBase profilePic
        {
            string  json = string.Empty;
            var     res  = new HttpResponseMessage();
            JObject jContent;

            if (ModelState.IsValid)
            {
                try
                {
                    UserDetailsDAL objUserDAL = new UserDetailsDAL();
                    // List<DashBoardBEL> UserMenus = objUserDAL.GetMenuMapping((((TrueWheels.Web.Models.UserLoginDetailsViewModel)(Session["userDetail"])).User_ID).ToString());
                    if (profileInfo.NewPassword == null)
                    {
                        profileInfo.NewPassword = profileInfo.Password;
                    }
                    //if (profileInfo.MobileNo == null)
                    //{
                    //    profileInfo.NewPassword = profileInfo.Password;
                    //}

                    UserMaintenanceViewModel objUserMaintenance = new UserMaintenanceViewModel();

                    objUserMaintenance.Personalinfo = objUserDAL.UpdateProfileInfo(profileInfo);
                    objUserMaintenance.Personalinfo.profilePic_Path = objUserMaintenance.Personalinfo.User_Id + ".png";
                    objUserMaintenance.Personalinfo.Full_Name       = objUserMaintenance.Personalinfo.First_Name + " " + objUserMaintenance.Personalinfo.Last_Name;
                    // ViewBag.DashBoardMenu = UserMenus;
                    if (!string.IsNullOrEmpty(objUserMaintenance.Personalinfo.ErrorMessage))
                    {
                        res.StatusCode = HttpStatusCode.Unauthorized;
                        jContent       = new JObject(
                            new JProperty("Success", false),
                            new JProperty("result",
                                          new JObject(

                                              new JProperty("Message", "Error Occured"),
                                              new JProperty("ErrorMessage", objUserMaintenance.Personalinfo.ErrorMessage),
                                              new JProperty("UserId", "0"))));
                    }
                    else
                    {
                        json           = JsonConvert.SerializeObject(objUserMaintenance);
                        res.StatusCode = HttpStatusCode.Accepted;
                        //res.Content = new StringContent(json);
                        jContent = JObject.Parse(json);
                        jContent = new JObject(new JProperty("Success", true),
                                               new JProperty("result",
                                                             new JObject(JObject.Parse(json))));
                    }
                }
                catch (Exception ex)
                {
                    res.StatusCode = HttpStatusCode.BadRequest;
                    jContent       = new JObject(
                        new JProperty("result",
                                      new JObject(
                                          new JProperty("Success", false),
                                          new JProperty("Message", ex.Message),
                                          new JProperty("ErrorMessage", ex.InnerException.ToString()),
                                          new JProperty("Transation", null))));
                }
            }
            else
            {
                var errorList = (from item in ModelState
                                 where item.Value.Errors.Any()
                                 select item.Value.Errors[0].ErrorMessage).ToList();
                res.StatusCode = HttpStatusCode.BadRequest;
                jContent       = new JObject(
                    new JProperty("result",
                                  new JObject(
                                      new JProperty("Success", false),
                                      new JProperty("Message", "Invalid Input"),
                                      new JProperty("ErrorMessage", errorList),
                                      new JProperty("Transation", null))));
            }
            res.Content = new StringContent(jContent.ToString());
            return(res);
        }
Exemple #4
0
        public static User ToEntity(this UserMaintenanceViewModel model)
        {
            var entity = AutoMapper.Mapper.Map <User>(model);

            return(entity);
        }
Exemple #5
0
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     _viewModel = (UserMaintenanceViewModel)this.DataContext;
 }
Exemple #6
0
 public UserMaintenanceControl()
 {
     InitializeComponent();
     //Connect to the instance of view model
     _viewModel = (UserMaintenanceViewModel)this.Resources["viewModel"];
 }