Example #1
0
        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));
            }
        }
Example #2
0
        /// <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();
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <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));
        }
Example #5
0
        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);
        }
Example #6
0
        /// <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);
        }
Example #7
0
        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));
            }
        }
Example #8
0
 private void ValidateNotificationTypeModel(NotificationTypeDomain notificationType)
 {
     ValidationHelper.NotNull(notificationType, NotificationMessages.NotificationTypeNotProvided);
     ValidationHelper.NotNullOrWhitespace(notificationType.Name, NotificationMessages.NotificationTypeNameEmpty);
     ValidationHelper.NotNullOrWhitespace(notificationType.Code, NotificationMessages.NotificationTypeCodeEmpty);
 }