Пример #1
0
        public ActionResult Remove(int packageId)
        {
            var request = new RemovePackageRequest
            {
                IdentityToken = this.FormsAuthentication.GetAuthenticationToken(),
                Id = packageId
            };
            var response = this.packagesService.RemovePackage(request);
            var result = new PackageViewModel
            {
                Id = packageId,
                Message = response.Message ?? DashboardViewResources.PackageRemovedSuccess,
                MessageType = response.MessageType.ToString()
            };

            var jsonNetResult = new JsonNetResult
            {
                Formatting = (Formatting)Newtonsoft.Json.Formatting.Indented,
                Data = result
            };
            return jsonNetResult;
        }
Пример #2
0
        /// <summary>
        /// Remove package completely.
        /// </summary>
        /// <param name="request">
        /// The remove package request.
        /// </param>
        /// <returns>
        /// The remove package response.
        /// </returns>
        public RemovePackageResponse RemovePackage(RemovePackageRequest request)
        {
            var response = new RemovePackageResponse { MessageType = MessageType.Success };

            var user = this.userRepository.GetUserWithPackagesByEmail(request.IdentityToken);

            if (user != null)
            {
                try
                {
                    var result = user.RemovePackage(request.Id);
                    if (result)
                    {
                        this.packageRepository.RemovePackage(request.Id);
                    }
                    else
                    {
                        response.MessageType = MessageType.Warning;
                        response.Message = DashboardViewResources.PackageCannotBeRemoved;
                    }
                }
                catch (Exception ex)
                {
                    response.MessageType = MessageType.Error;
                    response.Message = ex.Message;
                }
            }

            return response;
        }