public async Task <IActionResult> AddAndEditCheckList(CheckListCustom 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 CheckListDAL busines layer CommonResponseWithIds response = new CommonResponseWithIds(); response = checkListMaster.AddAndEditCheckList(data, userId); return(Ok(response)); }
/// <summary> /// Add and Edit Document /// </summary> /// <param name="data"></param> /// <param name="userId"></param> /// <returns></returns> public CommonResponseWithIds AddAndEditCheckList(CheckListCustom data, long userId) { CommonResponseWithIds obj = new CommonResponseWithIds(); try { var res = db.CheckListMaster.Where(m => m.CheckListName == data.checkListName && m.CheckListVersion == data.checkListVersion && m.IsDeleted == false && m.IsActive == true).FirstOrDefault(); if (res == null) { try { CheckListMaster item = new CheckListMaster(); item.CheckListName = data.checkListName.Trim(); item.CheckListDescription = data.checkListDescription; item.CheckListOwner = data.checkListOwner; item.CheckListVersion = data.checkListVersion; item.CheckListCategoryId = data.checkListCategoryId; item.CheckListTypeId = data.checkListTypeId; item.CheckListGroup = data.checkListGroup; //Mani item.EstimatedEndTime = data.estimatedTime; //Mani item.IsActive = true; item.IsDeleted = false; item.CreatedBy = userId; item.CreatedOn = DateTime.Now; db.CheckListMaster.Add(item); db.SaveChanges(); obj.response = ResourceResponse.AddedSucessfully; obj.isStatus = true; obj.id = item.CheckListId; } 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.CheckListName = data.checkListName; res.CheckListDescription = data.checkListDescription; res.CheckListOwner = data.checkListOwner; res.CheckListVersion = data.checkListVersion; res.CheckListCategoryId = data.checkListCategoryId; res.CheckListTypeId = data.checkListTypeId; res.CheckListGroup = data.checkListGroup; res.EstimatedEndTime = data.estimatedTime; res.ModifiedBy = userId; res.ModifiedOn = DateTime.Now; db.SaveChanges(); obj.response = ResourceResponse.UpdatedSucessfully; obj.isStatus = true; obj.id = data.checkListId; } 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); }