public bool deleteInviteCutomer(int CustomerId) { var inviteCustomerList = _db.PerformanceCustomerDetails.Where(x => x.InviteCustomer_Id == CustomerId).ToList(); foreach (var item in inviteCustomerList) { PerformanceCustomerDetail delete = inviteCustomerList.Where(x => x.Id == item.Id).FirstOrDefault(); _db.PerformanceCustomerDetails.Remove(delete); _db.SaveChanges(); var deleteJSON = _db.EmployeePerformanceCustomerSegmentJSONDetails.Where(x => x.PerCustomerdetailId == item.Id).ToList(); foreach (var JSONitem in deleteJSON) { EmployeePerformanceCustomerSegmentJSONDetail custoJSON = deleteJSON.Where(x => x.Id == JSONitem.Id).FirstOrDefault(); _db.EmployeePerformanceCustomerSegmentJSONDetails.Remove(custoJSON); } } return(true); }
public int saveInviteCustomer(string OverallScoreString, string Comments, int PerReviewId, int CustomerId, int EmpId, string JSONCustomerSegment, string JSONJobRoleSegment, string EmpPerfDetailId) { //var ExistPerformance = _db.PerformanceCustomerDetails.Where(x => x.Performance_Id == PerReviewId && x.InviteCustomer_Id == CustomerId).ToList(); //if (ExistPerformance != null && ExistPerformance.Count > 0) //{ // bool delete = deleteInviteCutomer(CustomerId); //} PerformanceCustomerDetail custDetails = new PerformanceCustomerDetail(); if (!string.IsNullOrEmpty(EmpPerfDetailId) && EmpPerfDetailId != "0") { custDetails.Id = Convert.ToInt32(EmpPerfDetailId); //Update OverAllScore Of Employee } custDetails.Performance_Id = PerReviewId; custDetails.InviteCustomer_Id = CustomerId; // custDetails.OverallScoreJSON = OverallScoreString; custDetails.InviteStatus = "Invite"; custDetails.Comments = Comments; custDetails.IsArchived = false; custDetails.EmployeeId = EmpId; custDetails.CusomerSegmentsJSON = JSONCustomerSegment; custDetails.LastModifiedBy = SessionProxy.UserId; custDetails.LastModifiedDate = DateTime.Now; _db.PerformanceCustomerDetails.Add(custDetails); _db.SaveChanges(); JavaScriptSerializer js = new JavaScriptSerializer(); EditSegmentViewModel model = new EditSegmentViewModel(); if (!string.IsNullOrEmpty(JSONCustomerSegment)) { model.CustomerSeg = js.Deserialize <List <CustomerSegment> >(JSONCustomerSegment); foreach (var item in model.CustomerSeg) { item.CustomerQueListData = js.Deserialize <List <CustomerQuestionModel> >(item.QueationType); } } if (!string.IsNullOrEmpty(JSONJobRoleSegment)) { model.JobRoleSeg = js.Deserialize <List <JobRoleSegment> >(JSONJobRoleSegment); foreach (var item in model.JobRoleSeg) { item.JobRoleQueListData = js.Deserialize <List <JobRoleQuestionModel> >(item.QueationType); } } EmployeePerformanceCustomerSegmentJSONDetail custoJSON = new EmployeePerformanceCustomerSegmentJSONDetail(); if (model.CustomerSeg != null && model.CustomerSeg.Count > 0) { foreach (var item in model.CustomerSeg) { foreach (var data in item.CustomerQueListData) { custoJSON.CustomerSegId = item.CustoIds; custoJSON.PerCustomerdetailId = custDetails.Id; custoJSON.QueId = Convert.ToInt32(data.QueId); custoJSON.Score = data.Score; custoJSON.Comments = data.Comments; custoJSON.Archived = false; custoJSON.UserIdCreatedBy = SessionProxy.UserId; custoJSON.UserIdCreatedDate = DateTime.Now; custoJSON.LastModifiedBy = SessionProxy.UserId; custoJSON.LastModifiedDate = DateTime.Now; _db.EmployeePerformanceCustomerSegmentJSONDetails.Add(custoJSON); _db.SaveChanges(); } } } EmployeePerformanceJobRoleSegmentJSONDetail jobroleJSON = new EmployeePerformanceJobRoleSegmentJSONDetail(); if (model.JobRoleSeg != null && model.JobRoleSeg.Count > 0) { foreach (var item in model.JobRoleSeg) { foreach (var data in item.JobRoleQueListData) { jobroleJSON.PerCustomerdetailId = custDetails.Id; jobroleJSON.JobRoleSegId = item.JobRoleIds; jobroleJSON.QueId = Convert.ToInt32(data.QueId); jobroleJSON.Score = data.Score; jobroleJSON.Comment = data.Comments; jobroleJSON.Archived = false; jobroleJSON.UserIdCreatedBy = SessionProxy.UserId; jobroleJSON.UserIdCreatedDate = DateTime.Now; jobroleJSON.LastModifiedBy = SessionProxy.UserId; jobroleJSON.LastModifiedDate = DateTime.Now; _db.EmployeePerformanceJobRoleSegmentJSONDetails.Add(jobroleJSON); _db.SaveChanges(); } } } int EmpPerfDeId = Convert.ToInt32(EmpPerfDetailId); var CalculateCustomerScore = _db.EmployeePerformanceCustomerSegmentJSONDetails.Where(x => x.PerCustomerdetailId == EmpPerfDeId && x.Archived == false).ToList(); if (CalculateCustomerScore.Count > 0) { int TotalCoreScore = 0; double AvgQueCoreScore = 0; foreach (var item in CalculateCustomerScore) { TotalCoreScore = TotalCoreScore + Convert.ToInt32(item.Score); } AvgQueCoreScore = TotalCoreScore / CalculateCustomerScore.Count; var EmployeePerf = _db.PerformanceCustomerDetails.Where(x => x.Id == EmpPerfDeId).FirstOrDefault(); EmployeePerf.CustomerScore = Convert.ToString(AvgQueCoreScore); EmployeePerf.LastModifiedDate = DateTime.Now; EmployeePerf.LastModifiedBy = SessionProxy.UserId; _db.SaveChanges(); } return(custDetails.Id); }