Ejemplo n.º 1
0
        public BaseResponse <UserNotification> AddUserNotification(UserNotification model)
        {
            var response = new BaseResponse <UserNotification>();
            var errors   = Validate <UserNotification>(model, new UserNotificationValidator());

            if (errors.Count() > 0)
            {
                BaseResponse <UserNotification> errResponse = new BaseResponse <UserNotification>(model, errors);
                errResponse.IsSuccess = false;
                return(errResponse);
            }
            var userNotification = _userNotificationRepository.FindBy(x => x.UserId == model.UserId && x.DeviceId == model.DeviceId).FirstOrDefault();

            if (userNotification != null)
            {
                userNotification.ClientId = model.ClientId;
                response.Value            = _userNotificationRepository.Edit(userNotification);
                return(response);
            }
            try
            {
                response.Value = _userNotificationRepository.Add(model);
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }