//Update
        public async Task <NotificationResponse> UpdateNotification(int id, UpdateNotificationRequest model)
        {
            var notification = await getNotification(id);

            if (notification == null)
            {
                throw new AppException("Update Notification failed");
            }
            //_mapper.Map(model, notification);
            if (notification.Status < model.Status)
            {
                notification.Status = model.Status;
            }
            _context.Notifications.Update(notification);
            await _context.SaveChangesAsync();

            var notificationResponse = _mapper.Map <NotificationResponse>(notification);

            var actionOwner = await _accountService.GetById(notificationResponse.ActionOwnerId);

            bool IsActionOwnerNameNull = actionOwner.Name == null;

            notificationResponse.ActionOwnerName = IsActionOwnerNameNull ? "" : actionOwner.Name;

            notificationResponse.ActionOwnerAvatarPath = actionOwner.AvatarPath;

            var receiver = await _accountService.GetById(notificationResponse.ReiceiverId);

            bool IsReceiverNull = receiver.Name == null;

            notificationResponse.ReiceiverName = IsReceiverNull ? "" : receiver.Name;
            return(notificationResponse);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update a v1 notification
        /// </summary>
        /// <param name="notification">Entity containing the v1 data of the notification to update</param>
        public void UpdateNotification(UpdateNotificationV1 notification)
        {
            const string FunctionAdmin = "updateNotification";
            const string Function      = "notification";

            if (notification.Published.HasValue && isAdminConnection)
            {
                throw new Exception("Published cannot be updated through admin connection. Use " + (notification.Published.Value ? "PublishNotification" : "DeleteNotification"));
            }

            notification.Check(isAdminConnection); // update with only ID and Puplished should be possible!

            UpdateNotificationRequest request = new UpdateNotificationRequest()
            {
                notificationId = notification.NotificationId,
                message        = notification.Message,
                timespans      = (notification.Timespans == null || notification.Timespans.Count() == 0) ? new UpdateNotificationRequest.Timespan[] { } : notification.Timespans.Select(t => new UpdateNotificationRequest.Timespan()
                {
                    start = t.Start.AsString(), end = t.End.AsString()
                }).ToArray(),
                data       = notification.Data,
                matchRange = notification.MatchRange,
                published  = notification.Published
            };

            HttpWebRequest webRequest = GetWebRequestAndSendRequest("PUT", isAdminConnection ? FunctionAdmin : Function, request, null, isAdminConnection ? null : notification.NotificationId);

            UpdateNotificationResponse response = GetJSONresponse <UpdateNotificationResponse>(webRequest);

            response.Check();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Updates a notification.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the UpdateNotification service method.</param>
        ///
        /// <returns>The response from the UpdateNotification service method, as returned by Budgets.</returns>
        /// <exception cref="Amazon.Budgets.Model.DuplicateRecordException">
        /// The budget name already exists. Budget names must be unique within an account.
        /// </exception>
        /// <exception cref="Amazon.Budgets.Model.InternalErrorException">
        /// An error on the server occurred during the processing of your request. Try again later.
        /// </exception>
        /// <exception cref="Amazon.Budgets.Model.InvalidParameterException">
        /// An error on the client occurred. Typically, the cause is an invalid input value.
        /// </exception>
        /// <exception cref="Amazon.Budgets.Model.NotFoundException">
        /// We can’t locate the resource that you specified.
        /// </exception>
        public virtual UpdateNotificationResponse UpdateNotification(UpdateNotificationRequest request)
        {
            var marshaller   = UpdateNotificationRequestMarshaller.Instance;
            var unmarshaller = UpdateNotificationResponseUnmarshaller.Instance;

            return(Invoke <UpdateNotificationRequest, UpdateNotificationResponse>(request, marshaller, unmarshaller));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initiates the asynchronous execution of the UpdateNotification operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the UpdateNotification operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public virtual Task <UpdateNotificationResponse> UpdateNotificationAsync(UpdateNotificationRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = UpdateNotificationRequestMarshaller.Instance;
            var unmarshaller = UpdateNotificationResponseUnmarshaller.Instance;

            return(InvokeAsync <UpdateNotificationRequest, UpdateNotificationResponse>(request, marshaller,
                                                                                       unmarshaller, cancellationToken));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Updates a notification.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the UpdateNotification service method.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        ///
        /// <returns>The response from the UpdateNotification service method, as returned by Budgets.</returns>
        /// <exception cref="Amazon.Budgets.Model.AccessDeniedException">
        /// You are not authorized to use this operation with the given parameters.
        /// </exception>
        /// <exception cref="Amazon.Budgets.Model.DuplicateRecordException">
        /// The budget name already exists. Budget names must be unique within an account.
        /// </exception>
        /// <exception cref="Amazon.Budgets.Model.InternalErrorException">
        /// An error on the server occurred during the processing of your request. Try again later.
        /// </exception>
        /// <exception cref="Amazon.Budgets.Model.InvalidParameterException">
        /// An error on the client occurred. Typically, the cause is an invalid input value.
        /// </exception>
        /// <exception cref="Amazon.Budgets.Model.NotFoundException">
        /// We can’t locate the resource that you specified.
        /// </exception>
        public virtual Task <UpdateNotificationResponse> UpdateNotificationAsync(UpdateNotificationRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = UpdateNotificationRequestMarshaller.Instance;
            options.ResponseUnmarshaller = UpdateNotificationResponseUnmarshaller.Instance;

            return(InvokeAsync <UpdateNotificationResponse>(request, options, cancellationToken));
        }
Exemplo n.º 6
0
        internal virtual UpdateNotificationResponse UpdateNotification(UpdateNotificationRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = UpdateNotificationRequestMarshaller.Instance;
            options.ResponseUnmarshaller = UpdateNotificationResponseUnmarshaller.Instance;

            return(Invoke <UpdateNotificationResponse>(request, options));
        }
        public async Task <IActionResult> MarkRead(int id, UpdateNotificationRequest request)
        {
            // Retrieves notification and user id
            int          userID       = Tools.GetUserID(User);
            Notification notification = await _repository.GetNotificationAsync(id);

            // Returns error if user doesn't own notification
            if (userID != notification.UserID)
            {
                return(Forbid());
            }

            // Updates notification and returns
            if (request.Read)
            {
                notification.Read = true;
                await _repository.SaveChangesAsync();
            }

            return(Json(new ApiNotification(notification)));
        }
Exemplo n.º 8
0
        public IHttpActionResult Update(UpdateNotificationRequest request)
        {
            request.ValidateNotNull();

            // convert from request model to domain model
            var notificationDomain = new NotificationDomain()
            {
                Id                   = request.Id,
                Title                = request.Title,
                Content              = request.Content,
                ExternalId           = request.ExternalId,
                NotificationStatusId = request.NotificationStatusId,
                NotificationTypeId   = request.NotificationTypeId
            };

            _notificationManipulation.UpdateNotification(notificationDomain);

            return(Ok(new UpdateNotificationResponse()
            {
                Success = Common.Enumerations.ResponseStatus.Succeeded
            }));
        }
        public async Task <ActionResult <NotificationResponse> > Update(int id, UpdateNotificationRequest model)
        {
            var notification = await _notificationService.UpdateNotification(id, model);

            return(Ok(notification));
        }
        public void ShowUpdateView()
        {
            var updatePopupRequestInfo = new UpdatePopupRequestInfo(App.UpdateApplicationInfo);

            UpdateNotificationRequest.Raise(updatePopupRequestInfo);
        }
        public IHttpActionResult UpdateNotification(UpdateNotificationRequest updateNotificationRequest)
        {
            var responses = new Responses();

            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (Utility.UserId < 0)
                {
                    return(BadRequest(Utility.INVALID_USER));
                }

                var notification = new Notification()
                {
                    NotificationId            = updateNotificationRequest.NotificationId,
                    RegulationId              = updateNotificationRequest.RegulationId,
                    MasterDirectionId         = updateNotificationRequest.MasterDirectionId,
                    NotificationNumber        = updateNotificationRequest.NotificationNumber,
                    NotificationName          = updateNotificationRequest.NotificationName,
                    NotificationDate          = updateNotificationRequest.NotificationDate,
                    NotificationEffectiveDate = updateNotificationRequest.NotificationEffectiveDate,
                    NotificationTypeId        = updateNotificationRequest.NotificationTypeId,
                    GSRNo           = updateNotificationRequest.GSRNo,
                    GSRDate         = updateNotificationRequest.GSRDate,
                    NotificationPDF = updateNotificationRequest.NotificationPDF,
                    GSRPDF          = updateNotificationRequest.GSRPDF,
                    ModifiedBy      = Utility.UserId
                };
                int result = iNotification.UpdateNotification(notification);

                switch (result)
                {
                case 1:
                    responses.Status      = Utility.SUCCESS_STATUS_RESPONSE;
                    responses.Description = "Notification updated successfully.";
                    break;

                case -2:
                    responses.Status      = Utility.ERROR_STATUS_RESPONSE;
                    responses.Description = "Notification already exists.";
                    break;

                case -3:
                    responses.Status      = Utility.ERROR_STATUS_RESPONSE;
                    responses.Description = "Notification doesn't exist.";
                    break;

                default:
                    responses.Status      = Utility.ERROR_STATUS_RESPONSE;
                    responses.Description = "Error while updating notification.";
                    break;
                }
            }
            catch (Exception ex)
            {
                responses.Status      = Utility.ERROR_STATUS_RESPONSE;
                responses.Description = "Error while updating notification.";

                Utility.WriteLog("UpdateNotification", updateNotificationRequest, "Error while updating notification. (NotificationAdminController)", ex.ToString());
            }
            return(Ok(responses));
        }