Example #1
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
Example #2
0
 public virtual void WiteLog(DateTime ngay, string maMayBan, string maNhanVien, string trangThai, string unitCode, string userName)
 {
     using (var context = new ERPContext())
     {
         var checkExist = context.AU_LOGs.FirstOrDefault(x => x.NGAY == ngay && x.MaMayBan == maMayBan && x.MaNhanVien == maNhanVien && x.TrangThai == trangThai);
         if (checkExist != null)
         {
             checkExist.NGAY       = ngay;
             checkExist.TrangThai  = trangThai;
             checkExist.MaNhanVien = maNhanVien;
             checkExist.MaMayBan   = maMayBan;
             checkExist.ThoiGian   = ngay.Hour.ToString() + ":" + ngay.Minute.ToString() + ":" + ngay.Second.ToString();
             if (!string.IsNullOrEmpty(trangThai) && trangThai == "LOGIN")
             {
                 checkExist.TinhTrang = 1;
             }
             else if (!string.IsNullOrEmpty(trangThai) && trangThai == "LOGOUT")
             {
                 checkExist.TinhTrang = 0;
             }
             checkExist.UnitCode    = unitCode;
             checkExist.IUpdateBy   = userName;
             checkExist.IUpdateDate = DateTime.Now;
             checkExist.ObjectState = ObjectState.Modified;
             context.AU_LOGs.Attach(checkExist);
             context.Entry(checkExist).State = EntityState.Modified;
             var iUpdate = context.SaveChanges();
         }
         else
         {
             AU_LOG instance = new AU_LOG();
             instance.Id         = Guid.NewGuid().ToString();
             instance.NGAY       = ngay;
             instance.TrangThai  = trangThai;
             instance.MaNhanVien = maNhanVien;
             instance.MaMayBan   = maMayBan;
             instance.ThoiGian   = ngay.Hour.ToString() + ":" + ngay.Minute.ToString() + ":" + ngay.Second.ToString();
             if (!string.IsNullOrEmpty(trangThai) && trangThai == "LOGIN")
             {
                 instance.TinhTrang = 1;
             }
             else if (!string.IsNullOrEmpty(trangThai) && trangThai == "LOGOUT")
             {
                 instance.TinhTrang = 0;
             }
             instance.UnitCode    = unitCode;
             instance.ICreateBy   = userName;
             instance.ICreateDate = DateTime.Now;
             instance.ObjectState = ObjectState.Added;
             context.AU_LOGs.Attach(instance);
             context.Entry(instance).State = EntityState.Added;
             var iInsert = context.SaveChanges();
         }
     }
 }
Example #3
0
        public IActionResult Edit(OrderRequest oModel)
        {
            Respuesta oRespuesta = new Respuesta();

            try
            {
                using (ERPContext db = new ERPContext())
                {
                    Order oOrder = db.Orders.Find(oModel.Id);
                    oOrder.Status           = oModel.Status;
                    oOrder.Priority         = oModel.Priority;
                    oOrder.Client           = oModel.Client;
                    oOrder.Employee         = oModel.Employee;
                    oOrder.DateOfCreation   = oModel.DateOfCreation;
                    oOrder.DateOfAssignment = oModel.DateOfAssignment;
                    oOrder.DateOfCompletion = oModel.DateOfCompletion;
                    oOrder.Address          = oModel.Address;
                    oOrder.Price            = oModel.Price;
                    db.Entry(oOrder).State  = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    db.SaveChanges();
                    oRespuesta.Exito = 1;
                }
            }
            catch (Exception ex)
            {
                oRespuesta.Mensaje = ex.Message;
            }

            return(Ok(oRespuesta));
        }
Example #4
0
 private static void SaveSupplierEditsToDatabaseContext(ERPContext context, Supplier editingSupplier,
                                                        Supplier editedSupplier)
 {
     context.Entry(editingSupplier).State = EntityState.Modified;
     DeepCopySupplierProperties(editedSupplier, editingSupplier);
     context.SaveChanges();
 }
Example #5
0
        public async Task <IActionResult> PutEmpleado([FromRoute] long id, [FromBody] Empleado empleado)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != empleado.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                _repo.Update(empleado);
                var save = await _repo.SaveAsync(empleado);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmpleadoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public IHttpActionResult PutPosition(int id, Position position)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != position.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PositionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #7
0
        public IHttpActionResult PutDailyFile(DailyFile dailyFile)
        {
            int id = dailyFile.Id;

            dailyFile.CreatedDate = DateTime.UtcNow;
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dailyFile.Id)
            {
                return(BadRequest());
            }

            _db.Entry(dailyFile).State = EntityState.Modified;

            try
            {
                _db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DailyFileExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #8
0
        public IActionResult Edit(EmployeeRequest oModel)
        {
            Respuesta oRespuesta = new Respuesta();

            try
            {
                using (ERPContext db = new ERPContext())
                {
                    Employee oEmployee = db.Employees.Find(oModel.Id);
                    oEmployee.Name            = oModel.Name;
                    oEmployee.Surname         = oModel.Surname;
                    oEmployee.Email           = oModel.Email;
                    oEmployee.PastOrders      = oModel.PastOrders;
                    oEmployee.CompletedOrders = oModel.CompletedOrders;
                    oEmployee.Salary          = oModel.Salary;
                    db.Entry(oEmployee).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    db.SaveChanges();
                    oRespuesta.Exito = 1;
                }
            }
            catch (Exception ex)
            {
                oRespuesta.Mensaje = ex.Message;
            }

            return(Ok(oRespuesta));
        }
Example #9
0
        public IActionResult Edit(ClientRequest oModel)
        {
            Respuesta oRespuesta = new Respuesta();

            try
            {
                using (ERPContext db = new ERPContext())
                {
                    Client oClient = db.Clients.Find(oModel.Id);
                    oClient.Name            = oModel.Name;
                    oClient.Email           = oModel.Email;
                    oClient.Cif             = oModel.Cif;
                    oClient.Address         = oModel.Address;
                    oClient.Phone           = oModel.Phone;
                    oClient.CompletedOrders = oModel.CompletedOrders;
                    db.Entry(oClient).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    db.SaveChanges();
                    oRespuesta.Exito = 1;
                }
            }
            catch (Exception ex)
            {
                oRespuesta.Mensaje = ex.Message;
            }

            return(Ok(oRespuesta));
        }
Example #10
0
 public void Update(ItemCategorySub ICS)
 {
     using (ERPContext context = new ERPContext())
     {
         context.Entry(ICS).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #11
0
 public void Update(Company company)
 {
     using (ERPContext context = new ERPContext())
     {
         context.Entry(company).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #12
0
 public static void ActivateSupplierInDatabase(Supplier supplier)
 {
     using (var context = new ERPContext())
     {
         context.Entry(supplier).State = EntityState.Modified;
         supplier.IsActive             = true;
         context.SaveChanges();
     }
 }
Example #13
0
 public static void ActivateCustomerInDatabase(Customer customer)
 {
     using (var context = new ERPContext())
     {
         context.Entry(customer).State = EntityState.Modified;
         customer.IsActive             = true;
         context.SaveChanges();
     }
 }
Example #14
0
 public static void ActivateItemInDatabase(Item item)
 {
     using (var context = new ERPContext())
     {
         context.Entry(item).State = EntityState.Modified;
         item.IsActive             = true;
         context.SaveChanges();
     }
 }
Example #15
0
 public static void ActivateItemInDatabase(Item item)
 {
     using (var context = new ERPContext())
     {
         context.Entry(item).State = EntityState.Modified;
         item.IsActive = true;
         context.SaveChanges();
     }
 }
Example #16
0
        public async Task <Artist> GetAsync(Guid id)
        {
            Artist artist = await _context.Artist.FindAsync(id);

            if (artist == null)
            {
                return(null);
            }

            _context.Entry(artist).State = EntityState.Detached;
            return(artist);
        }
Example #17
0
        public async Task <Genre> GetAsync(Guid id)
        {
            Genre genre = await _context.Genres.FindAsync(id);

            if (genre == null)
            {
                return(null);
            }

            _context.Entry(genre).State = EntityState.Detached;
            return(genre);
        }
        public static void MakePayment(PurchaseTransaction purchaseTransaction, decimal paymentAmount,
            decimal useCreditsAmount, string paymentMode)
        {
            using (var ts = new TransactionScope())
            {
                var context = new ERPContext();

                context.Entry(purchaseTransaction).State = EntityState.Modified;
                purchaseTransaction.Paid += paymentAmount + useCreditsAmount;
                purchaseTransaction.Supplier.PurchaseReturnCredits -= useCreditsAmount;

                RecordPaymentLedgerTransactionInDatabaseContext(context, purchaseTransaction, paymentAmount, paymentMode);

                context.SaveChanges();
                ts.Complete();
            }
        }
Example #19
0
        public static void MakePayment(PurchaseTransaction purchaseTransaction, decimal paymentAmount,
                                       decimal useCreditsAmount, string paymentMode)
        {
            using (var ts = new TransactionScope())
            {
                var context = new ERPContext();

                context.Entry(purchaseTransaction).State = EntityState.Modified;
                purchaseTransaction.Paid += paymentAmount + useCreditsAmount;
                purchaseTransaction.Supplier.PurchaseReturnCredits -= useCreditsAmount;

                RecordPaymentLedgerTransactionInDatabaseContext(context, purchaseTransaction, paymentAmount, paymentMode);

                context.SaveChanges();
                ts.Complete();
            }
        }
Example #20
0
        public async Task <IActionResult> Putproducto(int id, ProductoDto productoDto)
        {
            var producto = new Producto
            {
                Id                    = productoDto.Id,
                Descripcion           = productoDto.Descripcion,
                Saldoinicial          = productoDto.Saldoinicial,
                SaldoActual           = productoDto.SaldoActual,
                UnidadMedidaId        = productoDto.UnidadMedidaId,
                CostoPromedio         = productoDto.CostoPromedio,
                PrecioVenta           = productoDto.PrecioVenta,
                StockMinimo           = productoDto.StockMinimo,
                StockMaximo           = productoDto.StockMaximo,
                FechaCreacion         = productoDto.FechaCreacion,
                FechaModificacion     = productoDto.FechaModificacion,
                UsuarioCreacionId     = productoDto.UsuarioCreacionId,
                UsuarioModificacionId = productoDto.UsuarioModificacionId
            };

            if (id != producto.Id)
            {
                return(BadRequest());
            }
            context.Entry(producto).State = EntityState.Modified;
            try
            {
                await context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductoExists(producto.Descripcion.Trim()))
                {
                    return(NotFound());
                }
                else
                {
                    //throw;
                    return(BadRequest());
                }
            }
            return(NoContent());
        }
Example #21
0
        public IActionResult Edit(WarehouseRequest oModel)
        {
            Respuesta oRespuesta = new Respuesta();

            try
            {
                using (ERPContext db = new ERPContext())
                {
                    Warehouse oWarehouse = db.Warehouses.Find(oModel.Id);
                    oWarehouse.Category        = oModel.Category;
                    db.Entry(oWarehouse).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    db.SaveChanges();
                    oRespuesta.Exito = 1;
                }
            }
            catch (Exception ex)
            {
                oRespuesta.Mensaje = ex.Message;
            }

            return(Ok(oRespuesta));
        }
Example #22
0
 public Item Update(Item item)
 {
     _context.Entry(item).State = EntityState.Modified;
     return(item);
 }
Example #23
0
 public Company Update(Company address)
 {
     _context.Entry(address).State = EntityState.Modified;
     return(address);
 }
Example #24
0
 public static void ActivateCustomerInDatabase(Customer customer)
 {
     using (var context = new ERPContext())
     {
         context.Entry(customer).State = EntityState.Modified;
         customer.IsActive = true;
         context.SaveChanges();
     }
 }
Example #25
0
 public ArticlePriceListIn Update(ArticlePriceListIn articlePriceListIn)
 {
     _context.Entry(articlePriceListIn).State = EntityState.Modified;
     return(articlePriceListIn);
 }
Example #26
0
 public FAGText Update(FAGText address)
 {
     _context.Entry(address).State = EntityState.Modified;
     return(address);
 }
Example #27
0
 public Document Update(Document document)
 {
     _context.Entry(document).State = EntityState.Modified;
     return(document);
 }
Example #28
0
 public Article Update(Article article)
 {
     _context.Entry(article).State = EntityState.Modified;
     return(article);
 }
Example #29
0
 public CompanyType Update(CompanyType companyType)
 {
     _context.Entry(companyType).State = EntityState.Modified;
     return(companyType);
 }
Example #30
0
 public FAGBinary Update(FAGBinary country)
 {
     _context.Entry(country).State = EntityState.Modified;
     return(country);
 }
Example #31
0
 public DocumentPosition Update(DocumentPosition documentPosition)
 {
     _context.Entry(documentPosition).State = EntityState.Modified;
     return(documentPosition);
 }
Example #32
0
 public ArticlePriceListOut Update(ArticlePriceListOut articlePriceListOut)
 {
     _context.Entry(articlePriceListOut).State = EntityState.Modified;
     return(articlePriceListOut);
 }
Example #33
0
 private static void SaveSupplierEditsToDatabaseContext(ERPContext context, Supplier editingSupplier,
     Supplier editedSupplier)
 {
     context.Entry(editingSupplier).State = EntityState.Modified;
     DeepCopySupplierProperties(editedSupplier, editingSupplier);
     context.SaveChanges();
 }
Example #34
0
 public static void ActivateSupplierInDatabase(Supplier supplier)
 {
     using (var context = new ERPContext())
     {
         context.Entry(supplier).State = EntityState.Modified;
         supplier.IsActive = true;
         context.SaveChanges();
     }
 }
Example #35
0
 public ArticleGroup Update(ArticleGroup articleGroup)
 {
     _context.Entry(articleGroup).State = EntityState.Modified;
     return(articleGroup);
 }