public ServiceResponse <m_role> CreateRole(m_role role) { try { role.Code = "RO" + GenCode(); role.IsDelete = false; role.CreatedBy = "Administrator"; role.CreatedDate = DateTime.UtcNow; _ctx.m_roles.Add(role); _ctx.SaveChanges(); return(new ServiceResponse <m_role> { IsSuccess = true, Time = DateTime.UtcNow, Message = "Role Created", Data = role }); } catch (Exception e) { return(new ServiceResponse <m_role> { IsSuccess = false, Time = DateTime.UtcNow, Message = e.StackTrace, Data = null }); } }
public ServiceResponse <m_role> EditRole(m_role role) { role.UpdatedBy = "Administrator"; role.UpdatedDate = DateTime.UtcNow; try { _ctx.m_roles.Update(role); _ctx.SaveChanges(); return(new ServiceResponse <m_role> { IsSuccess = true, Message = "Role Deleted", Time = DateTime.UtcNow, Data = role }); } catch (Exception e) { return(new ServiceResponse <m_role> { IsSuccess = false, Message = e.StackTrace, Time = DateTime.UtcNow, Data = null }); } }
public static bool Delete(VMRole paramModel) { bool result = true; try { using (var db = new Markom_IDLEEntities()) { m_role a = db.m_role.Where(o => o.id == paramModel.id).FirstOrDefault(); if (a != null) { a.is_delete = true; db.SaveChanges(); } else { result = false; } } } catch (Exception hasError) { result = false; if (hasError.Message.ToLower().Contains("inner exception")) { Message = hasError.InnerException.InnerException.Message; } else { Message = hasError.Message; } } return(result); }
// delete public static bool hiddenRole(int id) { var result = false; MRoleVM data = MRoleRepo.getById(id); using (AppEntity db = new AppEntity()) { m_role item = db.m_role.Find(id); item.is_active = false; item.updated_by = 1; item.updated_date = DateTime.Now; try { db.SaveChanges(); result = true; } catch (Exception) { throw; } } return(result); }
//insert //menerima view model dari view public static bool insert(MRoleVM model) { bool result = false; //simpan datanya ke model using (AppEntity db = new AppEntity()) { m_role item = new m_role() { id = model.id, code = model.code, name = model.name, description = model.description, is_active = true, created_by = 1, created_date = DateTime.Now, updated_by = 1, updated_date = DateTime.Now, }; db.m_role.Add(item); try { db.SaveChanges(); result = true; } catch (Exception) { throw; } } return(result); }
public static bool Insert(VMRole paramModel) { bool result = true; try { using (var db = new Markom_IDLEEntities()) { m_role a = new m_role(); a.code = paramModel.code; a.name = paramModel.name; a.description = paramModel.description; a.is_delete = paramModel.is_delete; a.created_by = paramModel.created_by; a.created_date = paramModel.created_date; db.m_role.Add(a); db.SaveChanges(); } } catch (Exception hasError) { result = false; if (hasError.Message.ToLower().Contains("inner exception")) { Message = hasError.InnerException.InnerException.Message; } else { Message = hasError.Message; } } return(result); }
public static roleViewModel SerializeRole(m_role role) { return(new roleViewModel { Id = role.Id, Code = role.Code, Name = role.Name, Description = role.Description, IsDelete = role.IsDelete, CreatedBy = role.CreatedBy, CreatedDate = role.CreatedDate, UpdatedBy = role.UpdatedBy, UpdatedDate = role.UpdatedDate }); }
public ActionResult Create(VMRole paramModel) { try { RoleRepo.Message = string.Empty; //Create auto generate product_code using (var db = new Markom_IDLEEntities()) { string nol = ""; m_role cek = db.m_role.OrderByDescending(x => x.code).First(); int simpan = int.Parse(cek.code.Substring(3)); simpan++; for (int i = simpan.ToString().Length; i < 4; i++) { nol = nol + "0"; } paramModel.code = "MN" + nol + simpan; } paramModel.created_by = "Administrator"; paramModel.created_date = DateTime.Now; paramModel.is_delete = false; if (null == paramModel.name) { RoleRepo.Message = "Anda belum memasukan semua data. Silahkan ulangi kembali"; } if (string.IsNullOrEmpty(RoleRepo.Message)) { return(Json(new { success = RoleRepo.Insert(paramModel), message = paramModel.code }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = RoleRepo.Message }, JsonRequestBehavior.AllowGet)); } } catch (Exception hasError) { return(Json(new { success = false, message = hasError.Message }, JsonRequestBehavior.AllowGet)); } }
protected void gvResult_RowDeleting(object sender, GridViewDeleteEventArgs e) { this.PKID = int.Parse(e.Keys[0].ToString().Split(Constants.CHAR_COMMA)[0]); m_role cus = new m_role().SelectByID(this.PKID); if (cus != null) { cus.Delete(); menu_role menuRoleBiz = new menu_role(); menuRoleBiz.DeleteByRoleID(PKID); //Commit GeneralManager.Commit(); bindingData(); } }
public static Responses Update(M_RoleViewModel entity) { Responses result = new Responses(); try { using (var db = new MarcomContext()) { if (entity.Id != 0) { m_role role = db.m_role.Where(o => o.id == entity.Id).FirstOrDefault(); if (role != null) { role.code = entity.Code; role.name = entity.Name; role.description = entity.Description; role.is_delete = entity.IsDelete; role.updated_by = "Freeska"; role.updated_date = DateTime.Now; db.SaveChanges(); } } else { m_role role = new m_role(); role.code = entity.Code; role.name = entity.Name; role.description = entity.Description; role.is_delete = entity.IsDelete; role.created_by = "Freeska"; role.created_date = DateTime.Now; db.m_role.Add(role); db.SaveChanges(); } } } catch (Exception ex) { result.Message = ex.Message; result.Success = false; } return(result); }
// update public static bool Edit(MRoleVM model) { bool result = false; // simpan datanya ke model using (AppEntity db = new AppEntity()) { // get data dari database m_role item = db.m_role.Find(model.id); item.id = model.id; item.code = model.code; item.name = model.name; item.description = model.description; item.updated_by = 1; item.updated_date = DateTime.Now; try { db.SaveChanges(); result = true; } catch (Exception) { throw; } } return(result); }
private void initialPage() { lbCommandName.Text = CommandNameEnum.Edit.ToString(); m_role role = new m_role(); ddlRole.Items.Clear(); ddlRole.DataSource = role.SelectAll(); ddlRole.DataBind(); ddlRole.Items.Insert(0, new ListItem(Constants.PLEASE_SELECT, "")); m_title title = new m_title(); ddlTitle.Items.Clear(); ddlTitle.DataSource = title.SelectAll(); ddlTitle.DataBind(); ddlTitle.Items.Insert(0, new ListItem(Constants.PLEASE_SELECT, "")); m_type_of_test type_of_test = new m_type_of_test(); lstTypeOfTest.Items.Clear(); lstTypeOfTest.DataSource = type_of_test.SelectDistinct(); lstTypeOfTest.DataBind(); lstTypeOfTest.Items.Insert(0, new ListItem(Constants.PLEASE_SELECT, "")); fillinScreen(); ddlRole.Enabled = false; txtUser.Enabled = false; txtPassword.Enabled = true; txtEmail.Enabled = true; ddlTitle.Enabled = true; txtFirstName.Enabled = true; txtLastName.Enabled = true; btnSave.Enabled = true; btnCancel.Enabled = true; }
public static Responses Delete(int id) { Responses result = new Responses(); try { using (var db = new MarcomContext()) { m_role role = db.m_role.Where(o => o.id == id).FirstOrDefault(); if (role != null) { role.is_delete = true; db.SaveChanges(); } } } catch (Exception ex) { result.Message = ex.Message; result.Success = false; } return(result); }
public static string CreateRole(RoleViewModel paramDataRole) { string latestSaveCode = string.Empty; using (var db = new MarkomApplicationDBEntities()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { m_role c = new m_role(); c.code = RoleCode(); c.name = paramDataRole.name; c.description = paramDataRole.description; c.is_delete = paramDataRole.isDelete; c.create_by = paramDataRole.createBy; c.create_date = paramDataRole.createDate; db.m_role.Add(c); db.SaveChanges(); dbContextTransaction.Commit(); //get latest save code latestSaveCode = c.code; } catch (Exception ex) { Message = ex.Message; dbContextTransaction.Rollback(); //throw; } } } return(latestSaveCode); }
private void fillinScreen() { m_role role = new m_role().SelectByID(this.PKID); txtName.Text = role.name; }