public ActionResult UpdateGeneralInformation(ProfileModel Model, HttpPostedFileBase file) { UserBM CurrentUser = (UserBM)Session["User"]; if (CurrentUser != null) { if (Model.UserGeneralInformationModel.Id == 0) { if (file != null) { UserGeneralInformationBL UserGeneralInformationBL = new BL.BusinessLayer.UserGeneralInformationBL(); string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/Images/" + ImageName); file.SaveAs(physicalPath); UserGeneralInformationBM UserGeneralInformation = new UserGeneralInformationBM(); UserGeneralInformation.CommunityId = Model.UserGeneralInformationModel.CommunityId; UserGeneralInformation.SubCommunityId = Model.UserGeneralInformationModel.SubCommunityId; UserGeneralInformation.Image = "/Images/" + ImageName; UserGeneralInformation.UserId = CurrentUser.Id; UserGeneralInformation.CreatedBy = CurrentUser.Id; UserGeneralInformation.CreationDate = DateTime.Now; UserGeneralInformationBL.Create(UserGeneralInformation); if (!string.IsNullOrEmpty(Model.UserGeneralInformationModel.Password)) { CurrentUser.Password = Model.UserGeneralInformationModel.Password; UserBL userBL = new UserBL(); CurrentUser.CreationDate = DateTime.Now; userBL.UpdateUser(CurrentUser); Session["User"] = CurrentUser; } TempData["Success"] = "Record saved Successfully."; } } else { //update code UserGeneralInformationBM UserGeneralInformationBM = UserGeneralInformationBL.GetGeneralInformationByUserId(CurrentUser.Id); UserGeneralInformationBM.CommunityId = Model.UserGeneralInformationModel.CommunityId; UserGeneralInformationBM.SubCommunityId = Model.UserGeneralInformationModel.SubCommunityId; // UserGeneralInformationBM.Image = "/Images/" + ImageName; if (file != null) { string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/Images/" + ImageName); file.SaveAs(physicalPath); UserGeneralInformationBM.Image = "/Images/" + ImageName; } UserGeneralInformationBM.UserId = CurrentUser.Id; UserGeneralInformationBM.ModifiedBy = CurrentUser.Id; UserGeneralInformationBM.ModificationDate = DateTime.Now; UserGeneralInformationBL.Update(UserGeneralInformationBM); } } else { TempData["Error"] = "Please Login."; } return(RedirectToAction("Profile")); }
public ActionResult UpdateGeneralInformation(ProfileModel Model, HttpPostedFileBase file, FormCollection collection) { UserBM CurrentUser = SessionManager.InstanceCreator.Get<UserBM>(SessionKey.User); if (CurrentUser != null) { try { if (Model.UserGeneralInformationModel.Id == 0) { if (file != null) { UserGeneralInformationBL UserGeneralInformationBL = new BL.BusinessLayer.UserGeneralInformationBL(); string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/Images/" + ImageName); file.SaveAs(physicalPath); UserGeneralInformationBM UserGeneralInformation = new UserGeneralInformationBM(); UserGeneralInformation.Image = "/Images/" + ImageName; UserGeneralInformation.PhoneNumber = Model.UserGeneralInformationModel.PhoneNumber; UserGeneralInformation.Address1 = Model.UserGeneralInformationModel.Address1; UserGeneralInformation.Address2 = Model.UserGeneralInformationModel.Address2; UserGeneralInformation.FatherName = Model.UserGeneralInformationModel.FatherName; UserGeneralInformation.Status = Model.UserGeneralInformationModel.Status; UserGeneralInformation.UserId = CurrentUser.Id; UserGeneralInformation.CreatedBy = CurrentUser.Id; UserGeneralInformation.CreationDate = DateTime.Now; UserGeneralInformationBL.Create(UserGeneralInformation); // TempData["Success"] = "Record saved Successfully."; TempData["Success"] = "Record saved Successfully."; } } else { //update code UserGeneralInformationBM UserGeneralInformationBM = UserGeneralInformationBL.GetGeneralInformationByUserId(CurrentUser.Id); UserGeneralInformationBM.CommunityId = Model.UserGeneralInformationModel.CommunityId; UserGeneralInformationBM.SubCommunityId = Model.UserGeneralInformationModel.SubCommunityId; // UserGeneralInformationBM.Image = "/Images/" + ImageName; if (file != null) { string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/Images/" + ImageName); file.SaveAs(physicalPath); UserGeneralInformationBM.Image = "/Images/" + ImageName; } UserGeneralInformationBM.PhoneNumber = Model.UserGeneralInformationModel.PhoneNumber; UserGeneralInformationBM.Address1 = Model.UserGeneralInformationModel.Address1; UserGeneralInformationBM.Address2 = Model.UserGeneralInformationModel.Address2; UserGeneralInformationBM.FatherName = Model.UserGeneralInformationModel.FatherName; UserGeneralInformationBM.Status = Model.UserGeneralInformationModel.Status; UserGeneralInformationBM.UserId = CurrentUser.Id; UserGeneralInformationBM.ModifiedBy = CurrentUser.Id; UserGeneralInformationBM.ModificationDate = DateTime.Now; UserGeneralInformationBL.Update(UserGeneralInformationBM); TempData["Success"] = "Record saved Successfully."; } } catch (Exception ex) { TempData["Error"] = "An Error Occured."; } } else { TempData["Error"] = "Please Login."; } return RedirectToAction("EditProfile"); }