public void PlainField()
        {
            var customer = new Customer {
                Name = "Customer"
            };

            db.Add(customer);
            db.SaveChanges();

            customer.Name = "Updated";
            AssertModified(customer);
        }
        public async Task <bool> CreateAsync(CustomerEntity customer)
        {
            if (!IsIDExistsAsync(customer.CustomerCID).Result)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
        public async Task <IActionResult> Create([Bind("Id,Name,CountryCode")] Country country)
        {
            if (ModelState.IsValid)
            {
                _context.Add(country);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(country));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Address,MobileNo,Email,CityId")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", customer.CityId);
            return(View(customer));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,CountryId")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "CountryCode", city.CountryId);
            return(View(city));
        }
Example #6
0
 public int Add(Models.Customer item)
 {
     try
     {
         var NewItem = dbContext.Add(item);
         Save();
         return(NewItem.Entity.CustomerId);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Example #7
0
        public async Task <bool> AddCustomer(CustomerDbContext context, Customer customer)
        {
            var hasExisting = CheckIfRecordAlreadyExists(context.CustomerItems.ToList(), customer.FirstName);

            if (hasExisting)
            {
                return(false);
            }
            context.Add(customer);
            await context.SaveChangesAsync();

            return(true);
        }
Example #8
0
        public int Upsert(Customer customer)
        {
            var customerFromDb = Get(customer.FirstName, customer.LastName);

            if (customerFromDb == null)
            {
                _dbContext.Add(customer);
            }
            else
            {
                customerFromDb.updateFrom(customer);
                _dbContext.Update(customerFromDb);
            }

            return(_dbContext.SaveChanges());
        }
 public async Task <bool> CreateNewCustomer(Customer customer)
 {
     return(await Task.Run(() =>
     {
         var result = false;
         try
         {
             _customerContext.Add(customer);
             _customerContext.SaveChanges();
             result = true;
         }
         catch
         {
             throw;
         }
         return result;
     }));
 }