public ActionResult UpdateDepartment(DepartmentCustom data) { DepartmentDAL departmentDAL = new DepartmentDAL(); string result = departmentDAL.UpdateDepartment(data); ViewData["result"] = result; ModelState.Clear(); return(View()); }
public async Task <IActionResult> AddAndEditDepartment(DepartmentCustom data) { #region Authorization code var identity = HttpContext.User.Identity as ClaimsIdentity; string id = ""; string role = ""; if (identity != null) { IEnumerable <Claim> claims = identity.Claims; // or id = identity.Claims.Where(m => m.Type == ClaimTypes.Sid).Select(m => m.Value).FirstOrDefault(); role = identity.Claims.Where(m => m.Type == ClaimTypes.Role).Select(m => m.Value).FirstOrDefault(); } long userId = Convert.ToInt32(id); #endregion //calling DepartmentDAL busines layer CommonResponse response = new CommonResponse(); response = departmentMaster.AddAndEditDepartment(data, userId); return(Ok(response)); }
/// <summary> /// Update Department /// </summary> /// <param name="data"></param> /// <returns></returns> public string UpdateDepartment(DepartmentCustom data) { string result = ""; try { SqlConnection con = new SqlConnection(@"Data Source = (localdb)\MSSQLLocalDB; Initial Catalog = Test; Integrated Security = True"); SqlCommand cmd = new SqlCommand("UpdateDepartment", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@departmentName", data.departmentName); cmd.Parameters.AddWithValue("@departmentDescription", data.departmentDesc); cmd.Parameters.AddWithValue("@id", data.id); cmd.Parameters.AddWithValue("@modifiedOn", DateTime.Now); con.Open(); object res = cmd.ExecuteNonQuery(); con.Close(); return(result = "Item Added Successfully"); } catch (Exception ex) { return(result = "Item Not Added"); } }
/// <summary> /// Add and Edit Document /// </summary> /// <param name="data"></param> /// <param name="userId"></param> /// <returns></returns> public CommonResponse AddAndEditDepartment(DepartmentCustom data, long userId = 0) { CommonResponse obj = new CommonResponse(); try { var res = db.DepartmentMaster.Where(m => m.DepartmentId == data.departmentId).FirstOrDefault(); if (res == null) { try { DepartmentMaster item = new DepartmentMaster(); item.DepartmentName = data.departmentName; item.DepartmentDescription = data.departmentDescription; item.IsActive = true; item.IsDeleted = false; item.CreatedBy = userId; item.CreatedOn = DateTime.Now; db.DepartmentMaster.Add(item); db.SaveChanges(); obj.response = ResourceResponse.AddedSucessfully; obj.isStatus = true; } catch (Exception ex) { log.Error(ex); if (ex.InnerException != null) { log.Error(ex.InnerException.ToString()); } obj.response = ResourceResponse.ExceptionMessage; obj.isStatus = false; } } else { try { res.DepartmentName = data.departmentName; res.DepartmentDescription = data.departmentDescription; res.ModifiedBy = userId; res.ModifiedOn = DateTime.Now; db.SaveChanges(); obj.response = ResourceResponse.UpdatedSucessfully; obj.isStatus = true; } catch (Exception ex) { log.Error(ex); if (ex.InnerException != null) { log.Error(ex.InnerException.ToString()); } obj.response = ResourceResponse.ExceptionMessage; obj.isStatus = false; } } } catch (Exception ex) { log.Error(ex); if (ex.InnerException != null) { log.Error(ex.InnerException.ToString()); } obj.response = ResourceResponse.ExceptionMessage; obj.isStatus = false; } return(obj); }