Exemplo n.º 1
0
        public async Task <IActionResult> UpdatingPackages([FromBody] MembershipTypeForCreateDTO packageRq, int id)
        {
            try
            {
                var packageDb = await _repo.GetMembershipById(id);

                if (!string.IsNullOrEmpty(packageRq.Code))
                {
                    packageDb.Code = packageRq.Code;
                }

                if (!string.IsNullOrEmpty(packageRq.Name))
                {
                    packageDb.Name = packageRq.Name;
                }

                if (packageRq.PeriodicityDays > 0)
                {
                    packageDb.PeriodicityDays = packageRq.PeriodicityDays;
                }

                if (packageRq.Price > 0)
                {
                    packageDb.Price = packageRq.Price;
                }

                if (!string.IsNullOrEmpty(packageRq.ShortDescription))
                {
                    packageDb.ShortDescription = packageRq.ShortDescription;
                }

                if (!string.IsNullOrEmpty(packageRq.LongDescription))
                {
                    packageDb.LongDescription = packageRq.LongDescription;
                }

                packageDb.IsActive = packageRq.IsActive;

                if (packageDb.IsActive && (string.IsNullOrEmpty(packageRq.LongDescription) || string.IsNullOrEmpty(packageRq.ShortDescription)))
                {
                    return(BadRequest("Valor Invalido, Descripciones HTML (requeridas cuando se activa)"));
                }

                packageDb.ForSale = packageRq.ForSale;

                await this._repo.SaveAll();

                return(Ok());
            }
            catch (Exception ex)
            {
                new FileManagerHelper().RecordLogFile(MethodBase.GetCurrentMethod().ReflectedType.FullName, packageRq, ex, "Id : " + id.ToString());
                return(BadRequest(this._appSettings.Value.ServerError));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SavePackages([FromBody] MembershipTypeForCreateDTO packageRq)
        {
            try
            {
                if (string.IsNullOrEmpty(packageRq.Code))
                {
                    return(BadRequest("Valor Invalido, Codigo no enviado"));
                }

                if (string.IsNullOrEmpty(packageRq.Name))
                {
                    return(BadRequest("Valor Invalido, Nombre no enviado"));
                }

                if (packageRq.IsActive && packageRq.PeriodicityDays <= 0)
                {
                    return(BadRequest("Valor Invalido, Tiempo de vigencia"));
                }

                if (packageRq.IsActive && packageRq.Price <= 0)
                {
                    return(BadRequest("Valor Invalido, Precio"));
                }

                if (packageRq.IsActive && string.IsNullOrEmpty(packageRq.ShortDescription))
                {
                    return(BadRequest("Valor Invalido, Descripcion corta HTML"));
                }

                if (packageRq.IsActive && string.IsNullOrEmpty(packageRq.LongDescription))
                {
                    return(BadRequest("Valor Invalido, Descripcion larga HTML"));
                }

                var newPackage = this._mapper.Map <MembershipType>(packageRq);

                this._repo.Add(newPackage);

                await this._repo.SaveAll();


                return(Ok(newPackage.Id));
            }
            catch (Exception ex)
            {
                new FileManagerHelper().RecordLogFile(MethodBase.GetCurrentMethod().ReflectedType.FullName, packageRq, ex);
                return(BadRequest(this._appSettings.Value.ServerError));
            }
        }