//public async Task<ActionResult> DeleteAddress(int key) //{ // var to = Convert.ToInt16(Request.Headers.GetValues("To")[0]); // var type = Convert.ToInt32(Request.Headers.GetValues("Type")[0]); // var address = Request.Headers.GetValues("Address")[0]; // var notificationTypes = await _notificationService.GetNotificationTypes((NotificationCategory)type); // var notificationType = notificationTypes.FirstOrDefault(); // notificationType.NotificationTypeSetting.MarkAsModified(); // switch (to) // { // case (int)ToType.Recipients: // var recipientList = NotificationTypeMapper.toAddressViewModels(notificationType, to); // var recipientToRemove = recipientList.First(r => r.Address == address); // recipientList.Remove(recipientToRemove); // notificationType.NotificationTypeSetting.Recipients = recipientList.Any() ? string.Join(",", recipientList.Select(l => l.Address)) : null; // await _notificationService.SaveNotificationType(notificationType); // break; // case (int)ToType.RecipientCcs: // var ccsList = NotificationTypeMapper.toAddressViewModels(notificationType, to); // var ccToRemove = ccsList.First(r => r.Address == address); // ccsList.Remove(ccToRemove); // notificationType.NotificationTypeSetting.RecipientCcs = ccsList.Any() ? string.Join(",", ccsList.Select(l => l.Address)) : null; // await _notificationService.SaveNotificationType(notificationType); // break; // case (int)ToType.RecipientBccs: // var bccsList = NotificationTypeMapper.toAddressViewModels(notificationType, to); // var bccToRemove = bccsList.First(r => r.Address == address); // bccsList.Remove(bccToRemove); // notificationType.NotificationTypeSetting.RecipientBccs = bccsList.Any() ? string.Join(",", bccsList.Select(l => l.Address)) : null; // await _notificationService.SaveNotificationType(notificationType); // break; // default: // break; // } // return Json(key, JsonRequestBehavior.AllowGet); //} public async Task <ActionResult> DeleteAddress(int key, int To, int Type) { try { int to = To; int type = Type; var addressId = key; var notificationTypes = await _notificationService.GetNotificationTypes((NotificationCategory)type); var notificationType = notificationTypes.FirstOrDefault(); notificationType.NotificationTypeSetting.MarkAsModified(); switch (to) { case (int)ToType.Recipients: var recipientList = NotificationTypeMapper.ToAddressViewModels(notificationType, to); var recipientToRemove = recipientList.First(r => r.Id == addressId); recipientList.Remove(recipientToRemove); notificationType.NotificationTypeSetting.Recipients = recipientList.Any() ? string.Join(",", recipientList.Select(l => l.Address)) : null; await _notificationService.SaveNotificationType(notificationType); break; case (int)ToType.RecipientCcs: var ccsList = NotificationTypeMapper.ToAddressViewModels(notificationType, to); var ccToRemove = ccsList.First(r => r.Id == addressId); ccsList.Remove(ccToRemove); notificationType.NotificationTypeSetting.RecipientCcs = ccsList.Any() ? string.Join(",", ccsList.Select(l => l.Address)) : null; await _notificationService.SaveNotificationType(notificationType); break; case (int)ToType.RecipientBccs: var bccsList = NotificationTypeMapper.ToAddressViewModels(notificationType, to); var bccToRemove = bccsList.First(r => r.Id == addressId); bccsList.Remove(bccToRemove); notificationType.NotificationTypeSetting.RecipientBccs = bccsList.Any() ? string.Join(",", bccsList.Select(l => l.Address)) : null; await _notificationService.SaveNotificationType(notificationType); break; default: break; } var model = await GetNotificationManage(type, to); return(Json(model.Addresses, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message)); } }
public async Task <ActionResult> InsertAddress(CRUDModel <AddressViewModel> address) { var to = Convert.ToInt16(address.Params["To"]); var type = Convert.ToInt32(address.Params["Type"]); var notificationTypes = await _notificationService.GetNotificationTypes((NotificationCategory)type); var notificationType = notificationTypes.FirstOrDefault(); notificationType.NotificationTypeSetting.MarkAsModified(); switch (to) { case (int)ToType.Recipients: var recipientList = NotificationTypeMapper.ToAddressViewModels(notificationType, to); recipientList.Add(new AddressViewModel { Address = address.Value.Address }); notificationType.NotificationTypeSetting.Recipients = string.Join(",", recipientList.Select(l => l.Address)); var newRecipient = await _notificationService.SaveNotificationType(notificationType); address.Value.Id = recipientList.Last().Id + 1; break; case (int)ToType.RecipientCcs: var ccsList = NotificationTypeMapper.ToAddressViewModels(notificationType, to); ccsList.Add(new AddressViewModel { Address = address.Value.Address }); notificationType.NotificationTypeSetting.RecipientCcs = string.Join(",", ccsList.Select(l => l.Address)); var newCc = await _notificationService.SaveNotificationType(notificationType); address.Value.Id = ccsList.Last().Id + 1; break; case (int)ToType.RecipientBccs: var bccsList = NotificationTypeMapper.ToAddressViewModels(notificationType, to); bccsList.Add(new AddressViewModel { Address = address.Value.Address }); notificationType.NotificationTypeSetting.RecipientBccs = string.Join(",", bccsList.Select(l => l.Address)); var newBcc = await _notificationService.SaveNotificationType(notificationType); address.Value.Id = bccsList.Last().Id + 1; break; default: break; } return(Json(address.Value, JsonRequestBehavior.AllowGet)); }