Beispiel #1
0
 public async Task Create(CategoriaCP model)
 {
     try
     {
         _db.DbSetCategorias.Add(model);
         await _db.SaveChangesAsync();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message, e);
     }
 }
Beispiel #2
0
        public async Task <IHttpActionResult> UpdateEstado([FromBody] CategoriaCP model)
        {
            try
            {
                log.Info(new MDCSet(this.ControllerContext.RouteData));
                await _entityRepo.UpdateEstado(model);

                return(Ok("Registro actualizado exitosamente!"));
            }
            catch (Exception e)
            {
                log.Error(new MDCSet(this.ControllerContext.RouteData), e);
                return(InternalServerError(e));
            }
        }
Beispiel #3
0
        public async Task UpdateEstado(CategoriaCP model)
        {
            try
            {
                var _model = await _db.DbSetCategorias.FirstOrDefaultAsync(e => e.CatCPId == model.CatCPId);

                if (_model != null)
                {
                    _model.Estado = model.Estado;
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Beispiel #4
0
        public async Task Update(CategoriaCP model)
        {
            try
            {
                var _model = await _db.DbSetCategorias.FirstOrDefaultAsync(e => e.CatCPId == model.CatCPId);

                if (_model != null)
                {
                    _db.Entry(_model).CurrentValues.SetValues(model);
                    await _db.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
Beispiel #5
0
        public ActionResult Edit(HttpPostedFileBase file, Models.Admin cat)
        {
            try
            {
                CategoriaCEN cen = new CategoriaCEN();
                CategoriaCP  cp  = new CategoriaCP();
                int          n   = cen.get_ICategoriaCAD().ReadOIDDefault(cat.Categoria.Id).Articulo;

                String path2 = cen.get_ICategoriaCAD().ReadOIDDefault(cat.Categoria.Id).Imagen;
                if (file != null)
                {
                    path2 = file.FileName;
                }
                if (file != null)
                {
                    path2 = file.FileName;
                    if (file.ContentLength > 0)
                    {
                        //PARA UTILIZAR PATH SE NECESITA using System.IO
                        if ((Path.GetExtension(file.FileName).ToLower() == ".jpg") || (Path.GetExtension(file.FileName).ToLower() == ".png") ||
                            (Path.GetExtension(file.FileName).ToLower() == ".gif") || (Path.GetExtension(file.FileName).ToLower() == ".jpeg"))
                        {
                            var path = Path.Combine(Server.MapPath("~/Content/Uploads/Category"), path2);
                            file.SaveAs(path);
                        }
                    }
                }

                cen.Modify(cat.Categoria.Id, cat.Categoria.Nombre, n, path2);
                if (cat.Categoria.SuperId != 0)
                {
                    cen.Anyadir_supercat(cat.Categoria.Id, cat.Categoria.SuperId);
                }
                //else
                //  cen.Anyadir_supercat(cat.Categoria.Id, 0);
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                System.Web.HttpContext.Current.Session["PujaError"] = e.Message;
                return(RedirectToAction("../Registrado/Admin"));
            }
        }
Beispiel #6
0
        public async Task <IHttpActionResult> Create([FromBody] CategoriaCP model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                log.Info(new MDCSet(this.ControllerContext.RouteData));
                await _entityRepo.Create(model);

                return(Ok("Registro creado exitosamente!"));
            }
            catch (Exception e)
            {
                log.Error(new MDCSet(this.ControllerContext.RouteData), e);
                return(InternalServerError(e));
            }
        }
Beispiel #7
0
        public ActionResult Edit(Models.Admin cat)
        {
            try
            {
                CategoriaCEN cen = new CategoriaCEN();
                CategoriaCP  cp  = new CategoriaCP();
                int          n   = cen.get_ICategoriaCAD().ReadOIDDefault(cat.Categoria.Id).Articulo;

                cen.Modify(cat.Categoria.Id, cat.Categoria.Nombre, n, "");
                if (cat.Categoria.SuperId != 0)
                {
                    cen.Anyadir_supercat(cat.Categoria.Id, cat.Categoria.SuperId);
                }
                //else
                //  cen.Anyadir_supercat(cat.Categoria.Id, 0);
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                System.Web.HttpContext.Current.Session["PujaError"] = e.Message;
                return(RedirectToAction("../Registrado/Admin"));
            }
        }