public JsonResult ContactGroup(ContactGroupSetupModel model) { if (ModelState.IsValid) { string message; var statisticModel = _notificationService.SaveContactGroup(model, out message); if (statisticModel != null) { statisticModel.ContactNotificationSearchPartial = RenderPartialViewToString("Partials/_SearchQueries", statisticModel.ContactSearchDetailsModel); return(Json(new ResponseModel { Success = true, Message = message, Data = statisticModel })); } return(Json(new ResponseModel { Success = false, Message = message })); } return(Json(new ResponseModel { Success = false, Message = ModelState.BuildValidationMessages() })); }
/// <summary> /// Save contact group to notification /// </summary> /// <param name="model"></param> /// <param name="message"></param> /// <returns></returns> public ContactStatisticModel SaveContactGroup(ContactGroupSetupModel model, out string message) { var notification = GetById(model.Id); if (notification != null) { // Deserialize contact queries string in notification model to object var contactSearchModels = string.IsNullOrEmpty(notification.ContactQueries) ? new List <ContactSearchModel>() : SerializeUtilities.Deserialize <List <ContactSearchModel> >(notification.ContactQueries); // Number of contacts before new queries is added var totalExistingContacts = _contactService.SearchContacts(contactSearchModels).Count(); // Add new queries contactSearchModels.Add(model.ContactSearchModel); // Number of contact after new queries is added var totalContactsAfterAdded = _contactService.SearchContacts(contactSearchModels).Count(); // Number of contact in new queries var totalNewContactsExpected = _contactService.SearchContacts(model.ContactSearchModel).Count(); // Serialize contact queries and assign to notification model notification.ContactQueries = SerializeUtilities.Serialize(contactSearchModels); // Save new notification var response = Update(notification); if (response.Success) { message = string.Format("{0} duplicated contact(s). {1} contact(s) added successfully.", totalNewContactsExpected + totalExistingContacts - totalContactsAfterAdded, totalContactsAfterAdded - totalExistingContacts); return(new ContactStatisticModel { ExistedContacts = totalNewContactsExpected + totalExistingContacts - totalContactsAfterAdded, NewContacts = totalContactsAfterAdded - totalExistingContacts, TotalContacts = totalContactsAfterAdded, ContactSearchDetailsModel = new ContactSearchDetailsModel(model.ContactSearchModel) }); } message = T("Notification_Message_SavingContactGroupFailure"); return(null); } message = T("Notification_Message_ObjectNotFound"); return(null); }