public async Task <IActionResult> PutCustomersTypes([FromRoute] int id, [FromBody] CustomersTypes customersTypes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customersTypes.CustomerTypeId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <bool> PutUser(int id, User user)
        {
            if (user == null || id != user.UserId)
            {
                return(false);
            }

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

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

            return(true);
        }
Exemple #3
0
        public async Task <IActionResult> AddProduct([FromBody] Product objProduct)
        {
            if (!ModelState.IsValid)
            {
                return(new JsonResult("Error While Creating New Product"));
            }
            _db.Products.Add(objProduct);
            await _db.SaveChangesAsync();

            return(new JsonResult("Product Created Successfully"));
        }
        public async Task <IActionResult> AddCategory([FromBody] ProductCategory objCategory)
        {
            if (!ModelState.IsValid)
            {
                return(new JsonResult("Error While Creating New Category"));
            }
            _db.ProductCategories.Add(objCategory);
            await _db.SaveChangesAsync();

            return(new JsonResult("Category Created Successfully"));
        }
Exemple #5
0
 public async Task <IActionResult> AddEditEmployee(EmployeeViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             MyFirstTables emp   = new MyFirstTables();
             bool          IsNew = model.Id != 0 ? false : true;
             if (!IsNew)
             {
                 emp = await db.MyFirstTables.SingleOrDefaultAsync(a => a.Id == model.Id);
             }
             emp.Name = model.Name;
             emp.Age  = model.Age;
             var path = "";
             if (model.Profile.FileName != null)
             {
                 path = Path.Combine(
                     Directory.GetCurrentDirectory(), "wwwroot\\ProfilePicture", model.Profile.FileName);
                 using (var stream = new FileStream(path, FileMode.Create))
                 {
                     await model.Profile.CopyToAsync(stream);
                 }
             }
             emp.Profile      = model.Profile.FileName != null ? path : emp.Profile;
             emp.LastModified = model.LastModified;
             emp.Country      = model.Country;
             if (IsNew)
             {
                 await db.MyFirstTables.AddAsync(emp);
             }
             await db.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         //return NotFound(ex);
     }
     return(RedirectToAction("Index"));
 }