} //End public void Create public void Update(EmployeeuserVM poViewModel, HttpPostedFileBase poFileimage = null) { try { this.oModel = this.db.Employeeuser_infos.AsNoTracking().SingleOrDefault(fld => fld.ID == poViewModel.ID); this.oVM = new EmployeeVM(); this.oVM.InjectFrom(oModel); this.oVM_user = new UserdetailVM(); this.oViewModel = poViewModel; this.oViewModel.EMPUSER_ID = this.oModel.EMPUSER_ID; //Employee this.mapEmployee(); this.oCRUD.Update(oVM, poFileimage); this.oCRUD.Commit(); this.ID = this.oCRUD.ID; if (!this.oCRUD.isERR) { //User this.mapUser(); this.oCRUD_user.Update(oVM_user, poFileimage); this.oCRUD_user.Commit(); } //End if } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Update" + e.Message; } //End catch } //End public void Update
} //End public void Update //HQ public void Create(UserdetailVM poViewModel, HttpPostedFileBase poFileimage = null) { try { this.DELETE_FILE = false; this.oModel = new User(); //Map Form Data this.oModel.InjectFrom(poViewModel); //Set Field Header this.oModel.setFIELD_HEADER(hlpFlags_CRUDOption.CREATE); //DTA_STS this.oModel.DTA_STS = valFLAG.FLAG_DTA_STS_CREATE; //USER_STS this.oModel.USER_STS = valFLAG.FLAG_ACTIVE_ID; //Set Image file name if (poFileimage != null) { this.oFileuploaded = poFileimage; if ((this.oModel.USER_IMG == null) || (this.oModel.USER_IMG == "")) { this.oModel.USER_IMG = Utility_FileUploadDownload.setImage_User(); } //End if } //End if this.FILE_NAME = this.oModel.USER_IMG; //Process CRUD this.db.Users.Add(oModel); //db.SaveChanges(); //this.ID = oModel.ID; } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Create: " + e.Message; } //End catch } //End public void Create
} //End public void Commit() //MAPS private void mapUser() { if (this.oVM_user == null) { this.oVM_user = new UserdetailVM(); } this.oVM_user.ID = this.oViewModel.EMPUSER_ID; this.oVM_user.USERNAME = this.oViewModel.EMPUSER_USERNAME; this.oVM_user.ROLE_ID = this.oViewModel.EMPUSER_ROLEID; if ((this.oViewModel.EMPUSER_PASSWORD != null) && (this.oViewModel.EMPUSER_PASSWORD != "")) { this.oVM_user.PASSWORD = hlpObf.randomEncrypt(this.oViewModel.EMPUSER_PASSWORD); } this.oVM_user.EMAIL = this.oViewModel.EMPUSER_EMAIL; this.oVM_user.USER_IMG = this.oViewModel.EMPUSER_USERIMG; this.oVM_user.MDLE_ID = this.oViewModel.ROLE_MDLEID; this.oVM_user.RES_ID = this.ID; } //End Method
} //End public void Create public void Update(UserdetailVM poViewModel, HttpPostedFileBase poFileimage = null) { try { this.DELETE_FILE = false; this.oModel = this.db.Users.AsNoTracking().SingleOrDefault(fld => fld.ID == poViewModel.ID); int?nROLE_ID = oModel.ROLE_ID; //Map Form Data this.oModel.InjectFrom(poViewModel); //Get existing field value if (nROLE_ID == 7) { this.oModel.ROLE_ID = nROLE_ID; } //Set Field Header this.oModel.setFIELD_HEADER(hlpFlags_CRUDOption.UPDATE); //DTA_STS this.oModel.DTA_STS = valFLAG.FLAG_DTA_STS_UPDATE; //Set Image file name if (poFileimage != null) { this.oFileuploaded = poFileimage; if ((this.oModel.USER_IMG == null) || (this.oModel.USER_IMG == "")) { this.oModel.USER_IMG = Utility_FileUploadDownload.setImage_User(); } //End if } //End if this.FILE_NAME = this.oModel.USER_IMG; //Process CRUD this.db.Entry(oModel).State = EntityState.Modified; //db.SaveChanges(); //this.ID = oModel.ID; } //End try catch (Exception e) { isERR = true; this.ERRMSG = "CRUD - Update" + e.Message; } //End catch } //End public void Update
//Constructor 1 public User_Validation(UserdetailVM poViewModel) { oViewModel = poViewModel; } //End public User_Validation()