public async Task <IActionResult> AddAndEditCheckListLOTOTO(CheckListLOTOTOCustom 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 CheckListLOTOTODAL busines layer CommonResponse response = new CommonResponse(); response = checkListLOTOTOMaster.AddAndEditCheckListLOTOTO(data, userId); return(Ok(response)); }
/// <summary> /// Add and Edit Document /// </summary> /// <param name="data"></param> /// <param name="userId"></param> /// <returns></returns> public CommonResponse AddAndEditCheckListLOTOTO(CheckListLOTOTOCustom data, long userId = 0) { CommonResponse obj = new CommonResponse(); CommonFunction commonFunction = new CommonFunction(); try { var res = db.CheckListLototomaster.Where(m => m.LototoCheckListId == data.checkListLOTOTOId).FirstOrDefault(); if (res == null) { try { var stepCount = commonFunction.ChangeCheckListAndJobStepNumberOfPreviousItem(data.checkListMasterId, data.checkListGroupId, "LOTOTO", "CheckList"); CheckListLototomaster item = new CheckListLototomaster(); item.CheckListMasterId = data.checkListMasterId; item.CheckListGroupId = data.checkListGroupId; item.CheckListLockStepNumber = stepCount + 1; item.PositionDescription = data.positionDescription; item.IsLockOutRequired = data.isLockOutRequired; item.IsTagOutRequired = data.isTagOutRequired; item.IsTryOutRequired = data.isTryOutRequired; item.Remarks = data.remarks; item.IsActive = true; item.IsDeleted = false; item.IsAdminApproved = true; item.CreatedBy = userId; item.CreatedOn = DateTime.Now; db.CheckListLototomaster.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.CheckListMasterId = data.checkListMasterId; res.CheckListGroupId = data.checkListGroupId; res.CheckListLockStepNumber = data.checkListLockStepNumber; res.PositionDescription = data.positionDescription; res.IsLockOutRequired = data.isLockOutRequired; res.IsTagOutRequired = data.isTagOutRequired; res.IsTryOutRequired = data.isTryOutRequired; res.Remarks = data.remarks; 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); }
/// <summary> /// View Check List Details By Id /// </summary> /// <param name="checkListId"></param> /// <returns></returns> public CommonResponse ViewCheckListDetailsByCheckListAndGroupId(int checkListMasterId, int checkListGroupId) { CommonResponse obj = new CommonResponse(); try { var result = (from wf in db.CheckListMaster where wf.IsDeleted == false && wf.CheckListId == checkListMasterId select new { checkListId = wf.CheckListId, checkListName = wf.CheckListName, checkListDescription = wf.CheckListDescription, checkListOwner = wf.CheckListOwner, checkListVersion = wf.CheckListVersion, checkListCategoryId = wf.CheckListCategoryId, checkListCategoryName = db.CheckListCategoryMaster.Where(m => m.CheckListCategoryId == wf.CheckListCategoryId).Select(m => m.CheckListCategoryName).FirstOrDefault(), checkListTypeId = wf.CheckListTypeId, checkListTypeName = db.CheckListTypeMaster.Where(m => m.CheckListTypeId == wf.CheckListTypeId).Select(m => m.CheckListTypeName).FirstOrDefault(), isActive = wf.IsActive, checkListGroup = wf.CheckListGroup, }).FirstOrDefault(); if (result != null) { #region CheckList Details var list = result.checkListGroup.Split(',').Select(x => long.Parse(x.Trim())); var groups = (from wf in db.CheckListGroupMaster where wf.IsDeleted == false && list.Contains(wf.CheckListGroupId) select wf.CheckListGroupName).ToList(); CheckListDetails checkListCustom = new CheckListDetails(); checkListCustom.checkListId = result.checkListId; checkListCustom.checkListName = result.checkListName; checkListCustom.checkListVersion = result.checkListVersion; checkListCustom.checkListCategoryName = result.checkListCategoryName; checkListCustom.checkListTypeName = result.checkListTypeName; checkListCustom.checkListOwner = result.checkListOwner; checkListCustom.checkListGroup = String.Join(",", groups); checkListCustom.checkListGroupId = result.checkListGroup; checkListCustom.checkListGroupList = db.CheckListGroupMaster.Where(m => list.Contains(m.CheckListGroupId)).ToList(); #region Advance CheckList var checkListAdvanceList = (from wf in db.CheckListAdvanceMaster where wf.IsDeleted == false && wf.CheckListMasterId == checkListMasterId && wf.CheckListGroupId == checkListGroupId select new { checkListAdvanceId = wf.AdvanceCheckListId, checkListMasterId = wf.CheckListMasterId, checkListMasterName = db.CheckListMaster.Where(m => m.CheckListId == wf.CheckListMasterId).Select(m => m.CheckListName).FirstOrDefault(), checkListGroupId = wf.CheckListGroupId, checkListGroupName = db.CheckListGroupMaster.Where(m => m.CheckListGroupId == wf.CheckListGroupId).Select(m => m.CheckListGroupName).FirstOrDefault(), checkListStepNumber = wf.CheckListStepNumber, activityBeforeChangeOverDescription = wf.ActivityBeforeChangeOverDescription, remarks = wf.Remarks, isActive = wf.IsActive }).ToList(); List <CheckListAdvanceCustom> checkListAdvanceCustomList = new List <CheckListAdvanceCustom>(); foreach (var checkListAdvance in checkListAdvanceList) { CheckListAdvanceCustom checkListAdvanceCustom = new CheckListAdvanceCustom(); checkListAdvanceCustom.checkListAdvanceId = checkListAdvance.checkListAdvanceId; checkListAdvanceCustom.checkListMasterId = checkListAdvance.checkListMasterId; checkListAdvanceCustom.checkListGroupId = checkListAdvance.checkListGroupId; checkListAdvanceCustom.checkListStepNumber = checkListAdvance.checkListStepNumber; checkListAdvanceCustom.activityBeforeChangeOverDescription = checkListAdvance.activityBeforeChangeOverDescription; checkListAdvanceCustom.remarks = checkListAdvance.remarks; checkListAdvanceCustomList.Add(checkListAdvanceCustom); } checkListCustom.checkListAdvanceCustom = checkListAdvanceCustomList; #endregion #region Activity CheckList List <CheckListActivityBySubCategory> checkListActivityBySubCategories = new List <CheckListActivityBySubCategory>(); var subCategories = db.CheckListSubCategoryMaster.Where(m => m.IsDeleted == false).ToList(); foreach (var subCategory in subCategories) { CheckListActivityBySubCategory checkListActivityBySubCategory = new CheckListActivityBySubCategory(); checkListActivityBySubCategory.activitySubCategoryId = subCategory.CheckListSubCategoryId; checkListActivityBySubCategory.activitySubCategoryName = subCategory.CheckListSubCategoryName; var activityCheckList = (from wf in db.CheckListActivityMaster where wf.IsDeleted == false && wf.CheckListMasterId == checkListMasterId && wf.CheckListGroupId == checkListGroupId && wf.ActivitySubCategoryId == subCategory.CheckListSubCategoryId select new { checkListActivityId = wf.ActivityCheckListId, checkListMasterId = wf.CheckListMasterId, checkListMasterName = db.CheckListMaster.Where(m => m.CheckListId == wf.CheckListMasterId).Select(m => m.CheckListName).FirstOrDefault(), checkListGroupId = wf.CheckListGroupId, activitySubCategoryId = wf.ActivitySubCategoryId, activitySubCategoryName = db.CheckListSubCategoryMaster.Where(m => m.CheckListSubCategoryId == wf.ActivitySubCategoryId).Select(m => m.CheckListSubCategoryName).FirstOrDefault(), checkListGroupName = db.CheckListGroupMaster.Where(m => m.CheckListGroupId == wf.CheckListGroupId).Select(m => m.CheckListGroupName).FirstOrDefault(), checkListStepNumber = wf.CheckListStepNumber, activityDescription = wf.ActivityDescription, isActivityManditory = wf.IsActivityManditory, isPhotoManditory = wf.IsPhotoManditory, isBarCodeManditory = wf.IsBarCodeManditory, remarks = wf.Remarks, isActive = wf.IsActive, assetId = wf.AssetId, assetNumber = db.AssetMaster.Where(m => m.AssetId == wf.AssetId).Select(m => m.BarcodeAllocatedNumber).FirstOrDefault(), expectedCompletionTime = wf.ExpectedCompletionTime }).ToList(); List <CheckListActivityDetails> checkListActivityDetailsList = new List <CheckListActivityDetails>(); foreach (var activityCheck in activityCheckList) { CheckListActivityDetails checkListActivityDetails = new CheckListActivityDetails(); checkListActivityDetails.checkListActivityId = activityCheck.checkListActivityId; checkListActivityDetails.checkListMasterId = activityCheck.checkListMasterId; checkListActivityDetails.checkListGroupId = activityCheck.checkListGroupId; checkListActivityDetails.checkListStepNumber = activityCheck.checkListStepNumber; checkListActivityDetails.activityDescription = activityCheck.activityDescription; checkListActivityDetails.remarks = activityCheck.remarks; checkListActivityDetails.isActivityManditory = activityCheck.isActivityManditory; checkListActivityDetails.isPhotoManditory = activityCheck.isPhotoManditory; checkListActivityDetails.isBarCodeManditory = activityCheck.isBarCodeManditory; checkListActivityDetails.assetId = activityCheck.assetId; checkListActivityDetails.assetNumber = activityCheck.assetNumber; try { checkListActivityDetails.expectedCompletionTime = activityCheck.expectedCompletionTime; } catch (Exception ex) { } checkListActivityDetailsList.Add(checkListActivityDetails); } if (activityCheckList.Count > 0) { checkListActivityBySubCategory.checkListActivityDetails = checkListActivityDetailsList; checkListActivityBySubCategories.Add(checkListActivityBySubCategory); } } checkListCustom.checkListActivityBySubCategory = checkListActivityBySubCategories; #endregion #region LOTOTO CheckList List <CheckListLOTOTOCustom> checkListLOTOTOCustoms = new List <CheckListLOTOTOCustom>(); var checkListTOTOList = (from wf in db.CheckListLototomaster where wf.IsDeleted == false && wf.CheckListMasterId == checkListMasterId && wf.CheckListGroupId == checkListGroupId select new { checkListLOTOTOId = wf.LototoCheckListId, checkListMasterId = wf.CheckListMasterId, checkListMasterName = db.CheckListMaster.Where(m => m.CheckListId == wf.CheckListMasterId).Select(m => m.CheckListName).FirstOrDefault(), checkListGroupId = wf.CheckListGroupId, checkListGroupName = db.CheckListGroupMaster.Where(m => m.CheckListGroupId == wf.CheckListGroupId).Select(m => m.CheckListGroupName).FirstOrDefault(), checkListLockStepNumber = wf.CheckListLockStepNumber, positionDescription = wf.PositionDescription, isLockOutRequired = wf.IsLockOutRequired, isTagOutRequired = wf.IsTagOutRequired, isTryOutRequired = wf.IsTryOutRequired, remarks = wf.Remarks, isActive = wf.IsActive }).ToList(); foreach (var checkListLOTOTO in checkListTOTOList) { CheckListLOTOTOCustom checkListLOTOTOCustom = new CheckListLOTOTOCustom(); checkListLOTOTOCustom.checkListLOTOTOId = checkListLOTOTO.checkListLOTOTOId; checkListLOTOTOCustom.checkListMasterId = checkListLOTOTO.checkListMasterId; checkListLOTOTOCustom.checkListGroupId = checkListLOTOTO.checkListGroupId; checkListLOTOTOCustom.checkListLockStepNumber = checkListLOTOTO.checkListLockStepNumber; checkListLOTOTOCustom.positionDescription = checkListLOTOTO.positionDescription; checkListLOTOTOCustom.isLockOutRequired = checkListLOTOTO.isLockOutRequired; checkListLOTOTOCustom.isTagOutRequired = checkListLOTOTO.isTagOutRequired; checkListLOTOTOCustom.isTryOutRequired = checkListLOTOTO.isTryOutRequired; checkListLOTOTOCustom.remarks = checkListLOTOTO.remarks; checkListLOTOTOCustoms.Add(checkListLOTOTOCustom); } checkListCustom.checkListLOTOTOCustom = checkListLOTOTOCustoms; #endregion #endregion obj.response = checkListCustom; obj.isStatus = true; } else { obj.response = ResourceResponse.NoItemsFound; 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); }