Ejemplo n.º 1
0
        public ActionResult SendPackage(int packageId)
        {
            var request = new SendPackageRequest { PackageId = packageId };
            var response = this.packagesService.SendPackage(request);

            var jsonNetResult = new JsonNetResult
            {
                Formatting = (Formatting)Newtonsoft.Json.Formatting.Indented,
                Data = response.ConvertToPackageViewModel()
            };
            return jsonNetResult;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The send package.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="SendPackageResponse"/>.
        /// </returns>
        public SendPackageResponse SendPackage(SendPackageRequest request)
        {
            try
            {
                var package = this.packageRepository.GetPackageById(request.PackageId);
                package.ChangePackageStatus(PackageStatus.Sent);
                this.packageRepository.UpdatePackage(package);

                if (package.User.Activated)
                {
                    var profile = package.User.Profile;
                    var body = string.Format(
                        profile.GetEmailResourceString("PackageStatusChangedBody"),
                        package.Name,
                        package.Id,
                        profile.GetTranslatedPackageStatus("Paid"),
                        profile.GetTranslatedPackageStatus("Sent"),
                        profile.GetFullName());
                    this.emailService.SendMail(
                        EmailResources.EmailActivationFrom,
                        package.User.Email,
                        profile.GetEmailResourceString("PackageStatusChangedSubject"),
                        body);
                }

                var response = package.ConvertToSendPackageResponse();
                response.MessageType = MessageType.Success;
                response.Message = string.Format(PackageStatusResources.StatusChanged, PackageStatus.Sent);
                return response;
            }
            catch (Exception ex)
            {
                this.Logger.Log(ex.Message);
                return new SendPackageResponse { MessageType = MessageType.Error, Message = ex.Message };
            }
        }