public static CustomerRelationsModel Create(CustomerRelations customerRelations) { return(new CustomerRelationsModel { User = customerRelations.UserName, Action = customerRelations.Action == null ? "-" : customerRelations.Action.Name, Status = customerRelations.Status == null ? "-" : customerRelations.Status.Name, Rank = customerRelations.Rank == null ? "-" : customerRelations.Rank.Name, DateTime = customerRelations.Timestamp, Comment = customerRelations.Comment, Type = customerRelations.Type, PhoneNumber = customerRelations.PhoneNumber }); }
public JsonResult SaveEntry(string type, int action, int status, int?rank, string comment, int customerId, bool isBroker, string phoneNumber) { try { var actionItem = this._crmActionsRepository.Get(action); var statusItem = this._crmStatusesRepository.Get(status); var rankItem = rank.HasValue ? this._crmRanksRepository.Get(rank.Value) : null; var newEntry = new CustomerRelations { CustomerId = customerId, UserName = User.Identity.Name, Type = type, Action = actionItem, Status = statusItem, Rank = rankItem, Comment = comment, Timestamp = DateTime.UtcNow, IsBroker = isBroker, PhoneNumber = phoneNumber }; this._customerRelationsRepository.SaveOrUpdate(newEntry); this._customerRelationStateRepository.SaveUpdateState(customerId, false, null, newEntry); //Add SF activity var customer = this.customerRepository.ReallyTryGet(customerId); if (customer != null) { this._serviceClient.Instance.SalesForceAddActivity(this._context.UserId, customerId, new ActivityModel { Description = string.Format("{0}, {1}, {2}, {3}", type, actionItem.Name, statusItem.Name, comment), Email = customer.Name, Origin = customer.CustomerOrigin.Name, StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow, IsOpportunity = false, Originator = this._context.User.Name, Type = actionItem.Name, }); } return(Json(new { success = true, error = "" })); } catch (Exception e) { Log.ErrorFormat("Exception while trying to save customer relations new entry:{0}", e); return(Json(new { success = false, error = "Error saving new customer relations entry." })); } // try } // SaveEntry
public JsonResult ChangeRank(int customerId, int rankId) { try { var crm = new CustomerRelations { Rank = this._crmRanksRepository.Get(rankId), Timestamp = DateTime.UtcNow, Comment = "Rank change", UserName = User.Identity.Name, }; this._customerRelationsRepository.Save(crm); this._customerRelationStateRepository.SaveUpdateRank(customerId, crm); return(Json(new { success = true, error = "" })); } catch (Exception e) { Log.ErrorFormat("Exception while trying to change customer relations rank:{0}", e); return(Json(new { success = false, error = "Error saving new customer relations rank." })); } // try } // ChangeRank
}//HandleOneSms private void AddCrm(EzbobSmsMessage message) { if (!message.UserId.HasValue) { return; } var newEntry = new CustomerRelations { CustomerId = message.UserId.Value, UserName = "******", Type = "In", Action = this.smsActionItem, Status = this.noteStatusItem, Comment = message.Body, Timestamp = message.DateSent, IsBroker = false, PhoneNumber = message.From }; this.customerRelationsRepository.SaveOrUpdate(newEntry); this.customerRelationStateRepository.SaveUpdateState(message.UserId.Value, false, null, newEntry); }
public void MarkAsPending(int customerId, string actionItems, string costumeActionItemValue) { DateTime now = DateTime.UtcNow; List <int> checkedIds = GetCheckedActionItemIds(actionItems); bool changed = false; // "Close" action items var openActionItemsInDb = this.frequentActionItemsForCustomerRepository.GetAll().Where(x => x.CustomerId == customerId && x.UnmarkedDate == null); foreach (var openActionItem in openActionItemsInDb) { if (!checkedIds.Contains(openActionItem.ItemId)) { changed = true; openActionItem.UnmarkedDate = now; this.frequentActionItemsForCustomerRepository.SaveOrUpdate(openActionItem); } } // Insert new action items foreach (int checkedId in checkedIds) { if (!openActionItemsInDb.Any(x => x.ItemId == checkedId)) { changed = true; var newCheckedItem = new FrequentActionItemsForCustomer { CustomerId = customerId, ItemId = checkedId, MarkedDate = now }; this.frequentActionItemsForCustomerRepository.SaveOrUpdate(newCheckedItem); } } // Update costume action item Customer customer = this.customerRepository.Get(customerId); if (customer.CostumeActionItem != costumeActionItemValue) { changed = true; customer.CostumeActionItem = costumeActionItemValue; } if (changed) { var entry = new CustomerRelations { Action = this._crmActionsRepository.GetAll().FirstOrDefault(x => x.Name == "Action items change"), CustomerId = customerId, IsBroker = false, Rank = this._crmRanksRepository.GetAll().FirstOrDefault(x => x.Name == "High"), Status = this._crmStatusesRepository.GetAll().FirstOrDefault(x => x.Name == "Pending"), Timestamp = DateTime.UtcNow, Type = "Internal", UserName = User.Identity.Name }; this._customerRelationsRepository.SaveOrUpdate(entry); if (checkedIds.Count == 0 && string.IsNullOrEmpty(customer.CostumeActionItem)) { // Mark as waiting for decision customer.CreditResult = CreditResultStatus.WaitingForDecision; this.customerRepository.SaveOrUpdate(customer); } else { // Mark as pending customer.CreditResult = CreditResultStatus.ApprovedPending; this.customerRepository.SaveOrUpdate(customer); // Send mail this._serviceClient.Instance.SendPendingMails(this._context.UserId, customerId); } } }