public IHttpActionResult UpdateNotificationType(UpdateNotificationTypeRequest request) { try { request.ValidateNotNull(); NotificationTypeDomain domain = _notificationTypeManipulation.GetNotificationTypeById(request.Id); if (domain == null) { return(NotFound()); } domain.Name = request.Name; domain.Code = request.Code; _notificationTypeManipulation.UpdateNotificationType(domain); return(Ok(new UpdateNotificationTypeResponse() { Success = Common.Enumerations.ResponseStatus.Succeeded })); } catch (NsiBaseException e) { return(BadRequest(e.Message)); } }
/// <summary> /// Update notification type /// </summary> /// <param name="domain"></param> public void Update(NotificationTypeDomain domain) { NotificationType notificationType = _context.NotificationType.FirstOrDefault(x => x.NotificationTypeId == domain.Id); notificationType.FromDomainModel(domain); _context.SaveChanges(); }
/// <summary> /// Add a notification type /// </summary> /// <param name="domain"></param> /// <returns></returns> public int Add(NotificationTypeDomain domain) { NotificationType notificationType = new NotificationType().FromDomainModel(domain); _context.NotificationType.Add(notificationType); _context.SaveChanges(); return(notificationType.NotificationTypeId); }
/// <summary> /// Add notification type /// </summary> /// <param name="notificationType"></param> /// <returns></returns> public int AddNotificationType(NotificationTypeDomain notificationType) { ValidateNotificationTypeModel(notificationType); bool codeExists = _repository.GetAllByCode(notificationType.Code).Count > 0; ValidationHelper.IsFalse(codeExists, NotificationMessages.NotificationTypeCodeExists); return(_repository.Add(notificationType)); }
public static NotificationType FromDomainModel(this NotificationType obj, NotificationTypeDomain domain) { if (obj == null) { obj = new NotificationType(); } obj.NotificationTypeId = domain.Id; obj.Name = domain.Name; obj.Code = domain.Code; return(obj); }
/// <summary> /// Update notification type /// </summary> /// <param name="notificationType"></param> public void UpdateNotificationType(NotificationTypeDomain notificationType) { ValidateNotificationTypeModel(notificationType); ValidationHelper.GreaterThanZero(notificationType.Id, NotificationMessages.NotificationTypeIdInvalid); ValidationHelper.NotNull(_repository.GetById(notificationType.Id), NotificationMessages.NotificationTypeWithIdDoesNotExist); ICollection <NotificationTypeDomain> notificationTypeList = _repository.GetAllByCode(notificationType.Code); bool codeExists = notificationTypeList.Count > 1 || (notificationTypeList.Count == 1 && notificationTypeList.ElementAt(0).Id != notificationType.Id); ValidationHelper.IsFalse(codeExists, NotificationMessages.NotificationTypeCodeExists); _repository.Update(notificationType); }
public IHttpActionResult AddNotificationType(AddNotificationTypeRequest request) { try { request.ValidateNotNull(); NotificationTypeDomain domain = new NotificationTypeDomain(); domain.Name = request.Name; domain.Code = request.Code; int id = _notificationTypeManipulation.AddNotificationType(domain); return(Ok(new AddNotificationTypeResponse() { Data = id, Success = Common.Enumerations.ResponseStatus.Succeeded })); } catch (NsiBaseException e) { return(BadRequest(e.Message)); } }
private void ValidateNotificationTypeModel(NotificationTypeDomain notificationType) { ValidationHelper.NotNull(notificationType, NotificationMessages.NotificationTypeNotProvided); ValidationHelper.NotNullOrWhitespace(notificationType.Name, NotificationMessages.NotificationTypeNameEmpty); ValidationHelper.NotNullOrWhitespace(notificationType.Code, NotificationMessages.NotificationTypeCodeEmpty); }