Example #1
0
        public async Task <IActionResult> PutStatus(int id, Status status)
        {
            if (id != status.StatusId)
            {
                return(BadRequest());
            }

            _context.Entry(status).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StatusExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
        public HttpResponseMessage Put([FromBody] ProductosViewModel cambio)
        {
            try
            {
                if (cambio.Codpro == null || cambio.Codpro == "")
                {
                    throw new Exception("Producto no existe");
                }

                Productos pc = db.Productos.Where(a => a.Codpro == cambio.Codpro).FirstOrDefault();
                if (pc == null)
                {
                    throw new Exception("Producto no existe");
                }


                db.Entry(pc).State = EntityState.Modified;
                pc.Codpro          = cambio.Codpro;
                pc.Nompro          = cambio.Nompro;
                pc.Descripcion     = cambio.Descripcion;
                pc.CodCla          = cambio.CodCla;
                pc.CodBarras       = cambio.CodBarras;
                pc.Precio          = cambio.Precio;
                pc.Cantidad        = cambio.Cantidad;
                if (!String.IsNullOrEmpty(cambio.ImagenBase64))
                {
                    string Url = GuardaImagenBase64(cambio.ImagenBase64, "Productos", cambio.Codpro + "_" + cambio.CodBarras + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
                    pc.Imagen = Url;
                }
                else
                {
                    pc.Imagen = pc.Imagen;
                }
                pc.FechaCreacion = pc.FechaCreacion;
                pc.Activo        = true;

                db.SaveChanges();

                resp = new
                {
                    Success = true
                };

                return(Request.CreateResponse(HttpStatusCode.OK, resp));
            }
            catch (Exception ex)
            {
                // EncuestasRegistroController.GuardarBitacoraTxt(ex.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Example #3
0
        public async Task <IActionResult> PutMessage(int id, Message message)
        {
            if (id != message.MessageId)
            {
                return(BadRequest());
            }

            _context.Entry(message).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MessageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutSystemParam(int id, SystemParam systemParam)
        {
            if (id != systemParam.SystemParamId)
            {
                return(BadRequest());
            }

            User modifiedBy = _context.Users.Find(systemParam.ModifiedBy_UserId);

            systemParam.ModifiedBy        = modifiedBy;
            systemParam.ModifiedBy_UserId = modifiedBy.UserId;
            systemParam.ModifiedDate      = DateTime.Now;

            _context.Entry(systemParam).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SystemParamExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
        public async Task <IActionResult> PutNotificationItem(int id, NotificationItem notificationItem)
        {
            if (id != notificationItem.NotificationItemId)
            {
                return(BadRequest());
            }

            _context.Entry(notificationItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NotificationItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public void Update(TEntityDTO entity)
        {
            var mappedEntity = Mapper.Map <TEntity>(entity);

            Db.Entry(mappedEntity).State = EntityState.Modified;
            Db.SaveChanges();
        }
Example #7
0
        public async Task <IActionResult> UpdateUser(User newUser)
        {
            var user = _context.Users.Find(newUser.UserId);

            if (user == null)
            {
                return(NotFound());
            }

            user.DisplayName = newUser.DisplayName;
            user.FirstName   = newUser.FirstName;
            user.LastName    = newUser.LastName;
            user.Email       = newUser.Email;
            user.Password    = newUser.Password;

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }

            return(NoContent());
        }
        public HttpResponseMessage Put([FromBody] ProductosClasificacion cambio)
        {
            try
            {
                if (cambio.CodClasificacion == null || cambio.CodClasificacion == null)
                {
                    throw new Exception("Clasificacion no existe");
                }

                ProductosClasificacion pc = db.ProductosClasificacion.Where(a => a.CodClasificacion == cambio.CodClasificacion).FirstOrDefault();
                if (pc == null)
                {
                    throw new Exception("Clasificacion no existe");
                }


                db.Entry(pc).State = EntityState.Modified;
                pc.Nombre          = cambio.Nombre;

                db.SaveChanges();

                resp = new
                {
                    Success = true
                };

                return(Request.CreateResponse(HttpStatusCode.OK, resp));
            }
            catch (Exception ex)
            {
                // EncuestasRegistroController.GuardarBitacoraTxt(ex.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
 public ActionResult Edit(User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Example #10
0
 public ActionResult Edit(Brand brand)
 {
     if (ModelState.IsValid)
     {
         db.Entry(brand).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.categoryID = new SelectList(db.Categorys, "categoryID", "categoryName", brand.categoryID);
     return(View(brand));
 }
Example #11
0
        /// <summary>
        /// Add or update modifier and Item modifier
        /// </summary>
        /// <param name="modClient"></param>
        public void UpsertDeleteModiferAndItemModifier(Modifier modClient)
        {
            //load the modifier
            var modDb = _context.Modifier
                        .Include(_ => _.ItemModifier)
                        .FirstOrDefault(_ => _.Id == modClient.Id);

            if (modDb == null)
            {
                _context.Add(modClient);
            }
            else
            {
                //set values
                _context.Entry(modDb).CurrentValues.SetValues(modClient);

                //check what are in the db and update it
                foreach (var item in modClient.ItemModifier)
                {
                    var itemDb = modDb.ItemModifier.FirstOrDefault(_ => _.Id == item.Id);

                    if (itemDb == null)
                    {
                        item.ModifierId = modClient.Id;
                        _context.ItemModifier.Add(item);
                    }
                    else
                    {
                        _context.Entry <ItemModifier>(itemDb).CurrentValues.SetValues(item);
                    }
                }

                foreach (var item in modDb.ItemModifier)
                {
                    if (!modClient.ItemModifier.Any(_ => _.Id == item.Id))
                    {
                        _context.ItemModifier.Remove(item);
                    }
                }
            }
        }
 private async Task <bool> UpdateEntry(object obj)
 {
     _context.Entry(obj).State = EntityState.Modified;
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         return(false);
     }
     return(true);
 }
Example #13
0
        [HttpDelete]// [Route("api/Productos/Eliminar")]

        public async Task <IHttpActionResult> DesactivarUsuario(string nombre)
        {
            Usuarios user = db.Usuarios.Where(a => a.Nombre == nombre).FirstOrDefault();

            if (user == null)
            {
                return(NotFound());
            }

            db.Entry(user).State = EntityState.Modified;

            user.Activo = false;
            await db.SaveChangesAsync();

            return(Ok("OK"));
        }
Example #14
0
        public HttpResponseMessage Put([FromBody] Clientes cambio)
        {
            try
            {
                if (cambio.CodCliente == null || cambio.CodCliente == 0)
                {
                    throw new Exception("Cliente no existe");
                }

                Clientes pc = db.Clientes.Where(a => a.CodCliente == cambio.CodCliente).FirstOrDefault();
                if (pc == null)
                {
                    throw new Exception("Cliente no existe");
                }


                db.Entry(pc).State = EntityState.Modified;

                pc.Nombre    = cambio.Nombre;
                pc.Email     = cambio.Email;
                pc.Telefono  = cambio.Telefono;
                pc.Direccion = cambio.Direccion;


                db.SaveChanges();

                resp = new
                {
                    Success = true
                };

                return(Request.CreateResponse(HttpStatusCode.OK, resp));
            }
            catch (Exception ex)
            {
                // EncuestasRegistroController.GuardarBitacoraTxt(ex.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Example #15
0
        public async Task <HttpResponseMessage> PutAsync([FromBody] Proforma cambio)
        {
            var transaccion = db.Database.BeginTransaction();

            try
            {
                if (cambio.encProforma.NumProforma == null || cambio.encProforma.NumProforma == "")
                {
                    throw new Exception("Proforma no existe");
                }

                EncProforma pc = db.EncProforma.Where(a => a.NumProforma == cambio.encProforma.NumProforma).FirstOrDefault();
                if (pc == null)
                {
                    throw new Exception("Proforma no existe");
                }


                db.Entry(pc).State = EntityState.Modified;

                pc.CodCliente = cambio.encProforma.CodCliente;
                pc.CodUsuario = pc.CodUsuario;
                pc.FecFactura = DateTime.Now;
                pc.SubTotal   = cambio.encProforma.SubTotal;
                pc.Descuento  = cambio.encProforma.Descuento;
                pc.Impuesto   = cambio.encProforma.Impuesto;

                var dt = db.DetProforma.Where(a => a.NumProforma == pc.NumProforma).ToList();


                foreach (var item in dt)
                {
                    db.DetProforma.Remove(item);
                    await db.SaveChangesAsync();
                }


                foreach (var det in cambio.detProforma)
                {
                    det.NumProforma = cambio.encProforma.NumProforma;
                    det.Nompro      = db.Productos.Where(a => a.Codpro == det.Codpro).Select(u => u.Nompro).FirstOrDefault();
                    db.DetProforma.Add(det);
                    db.SaveChanges();
                }
                db.SaveChanges();

                resp = new
                {
                    Success = true
                };
                transaccion.Commit();

                return(Request.CreateResponse(HttpStatusCode.OK, resp));
            }
            catch (Exception ex)
            {
                transaccion.Rollback();
                // EncuestasRegistroController.GuardarBitacoraTxt(ex.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }