public ActionResult AssignMemberToBuyer(BuyerRelation relation) { var userId = GetUserId(); var currentLeadDetails = db.BuyerRelation.Where(b => b.BuyerId == relation.BuyerId).FirstOrDefault(); var validLead = db.BuyerRelation.Where(b => b.AssistantManagerId == userId && b.BuyerId == relation.BuyerId).FirstOrDefault(); if (validLead == null) { currentLeadDetails.MemberId = null; db.SaveChanges(); return(View("Error")); } else { var CurrentMemberAssigned = db.AssistantManagerToMemberRelations.Where(m => m.TeamMemberId == relation.MemberId && m.AssistantManagerId == userId).FirstOrDefault(); if (CurrentMemberAssigned != null) { currentLeadDetails.MemberId = relation.MemberId; } else { currentLeadDetails.MemberId = null; db.SaveChanges(); return(View("Error")); } } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AssignLeadToManager(Buyer_Detail bd) { try { Buyer_Detail BuyerDetail = new Buyer_Detail(); BuyerRelation BuyerRelation = new BuyerRelation(); var currentBuyerDetail = db.BuyerDetails.FirstOrDefault(b => b.BuyerId == bd.BuyerId); if (currentBuyerDetail == null) { return(HttpNotFound()); } currentBuyerDetail.ManagerAssigned = bd.ManagerAssigned; var currentBuyerRelation = db.BuyerRelation.FirstOrDefault(b => b.BuyerId == bd.BuyerId); if (currentBuyerRelation == null) { BuyerRelation.BuyerId = bd.BuyerId; BuyerRelation.ManagerId = bd.ManagerAssigned; BuyerRelation.UpdatedOn = DateTime.Now; db.BuyerRelation.Add(BuyerRelation); } else { currentBuyerRelation.ManagerId = bd.ManagerAssigned; currentBuyerRelation.UpdatedOn = DateTime.Now; currentBuyerRelation.AssistantManagerId = null; currentBuyerRelation.MemberId = null; } db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { return(View("Error")); } }