Пример #1
0
        public bool RemoveFromCart(Cart model)
        {
            var Authorize = db.carts.Where(x => x.Product_Id == model.Product_Id && x.userId == model.userId).FirstOrDefault();

            if (Authorize.Quantity == 1)
            {
                db.Entry(Authorize).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
                db.SaveChanges();
                return(true);
            }



            else if (Authorize.Quantity > 1)
            {
                Authorize.Quantity = Authorize.Quantity - model.Quantity;
                Authorize.Total    = Authorize.Total - (model.Quantity * Authorize.Price);
                db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            category.CId = id;

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

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

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> PutProduct([FromRoute] int id, [FromBody] Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.PId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #4
0
        public int UpdateConsumer(int id, [FromBody] Consumer consumer)
        {
            //var saved = false;
            //while (!saved)
            //{
            //    try
            //    {
            //        // Attempt to save changes to the database
            //        //_context.Entry(consumer).State = EntityState.Modified;
            //        int numberEntriesSaved = _context.SaveChanges();
            //        return numberEntriesSaved;
            //    }
            //    catch (DbUpdateConcurrencyException ex)
            //    {
            //        foreach (var entry in ex.Entries)
            //        {
            //            if (entry.Entity is Consumer)
            //            {
            //                var proposedValues = entry.CurrentValues;
            //                var databaseValues = entry.GetDatabaseValues();

            //                foreach (var property in proposedValues.Properties)
            //                {
            //                    var proposedValue = proposedValues[property];
            //                    var databaseValue = databaseValues[property];

            //                    // TODO: decide which value should be written to database
            //                    // proposedValues[property] = <value to be saved>;
            //                }

            //                // Refresh original values to bypass next concurrency check
            //                entry.OriginalValues.SetValues(databaseValues);
            //                return 0;
            //            }
            //            else
            //            {
            //                return 0;

            //                throw new NotSupportedException(
            //                    "Don't know how to handle concurrency conflicts for "
            //                    + entry.Metadata.Name);
            //            }
            //        }
            //    }
            //}
            //return 0;



            try
            {
                _context.Entry(consumer).State = EntityState.Modified;
                int numberEntriesSaved = _context.SaveChanges();
                return(numberEntriesSaved);
            }
            catch
            {
                throw;
            }
        }
Пример #5
0
        public async Task <IActionResult> PutProducts(int id, Products products)
        {
            if (id != products.ProductId)
            {
                return(BadRequest());
            }

            dbContext.Entry(products).State = EntityState.Modified;

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

            return(NoContent());
        }
Пример #6
0
 public ActionResult Edit([Bind(Include = "ID,FileNumber,Secret,Reminder,Title,FirstName,Surname,IdNumber,BirthDate,EmailAddress,ContactNumber,CellNumber,Address1,Address2,Address3,Address4,ConsultationFee,CurrentBalance")] Patient patient)
 {
     if (ModelState.IsValid)
     {
         db.Entry(patient).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(patient));
 }
Пример #7
0
        public async Task <IActionResult> UpdateDepartment(int id, TblDepartment department)
        {
            if (id != department.Id)
            {
                return(BadRequest());
            }

            _practiceContext.Entry(department).State = EntityState.Modified;
            await _practiceContext.SaveChangesAsync();

            return(Ok());
        }
 public void Update(T entity)
 {
     _dbContext.Entry(entity).State = EntityState.Modified;
     _dbContext.SaveChanges();
 }