예제 #1
0
        private int GetCustomerId()
        {
            var ctx = new TimeTrackerEntities();

            string selectedBillTo = cbBillTo.GetItemText(cbBillTo.SelectedItem);

            if (selectedBillTo.Length == 0)
            {
                var newBillTo = cbBillTo.Text;
                if (ctx.DCustomers.Any(x => x.CustomerName == newBillTo))
                {
                    var custRec = ctx.DCustomers.FirstOrDefault(x => x.CustomerName.ToUpper() == newBillTo.ToUpper());
                    if (custRec != null)
                    {
                        return(custRec.CustomerId);
                    }
                }
                else
                {
                    //create new Customer with input text.
                    var newCustomer = new DCustomer {
                        CustomerName = newBillTo
                    };
                    ctx.DCustomers.Add(newCustomer);
                    ctx.SaveChanges();
                    return(newCustomer.CustomerId);
                }
            }
            else
            {
                return(Int32.Parse(cbBillTo.SelectedValue.ToString()));
            }

            throw new DataException("Wierd Data Encountered!");
        }
예제 #2
0
        public async Task <ActionResult <DCustomer> > SignUp(CustomerDTO dto)
        {
            var customer1 = await _context.Customer.FirstOrDefaultAsync(c => c.Username == dto.customer.Username);


            if (customer1 != null)
            {
                return(NotFound(new { Message = "Already exists user with this username." }));
            }

            try
            {
                var newCustomer = new DCustomer()
                {
                    Username       = dto.customer.Username,
                    Password       = dto.customer.Password,
                    FirstName      = dto.customer.FirstName,
                    LastName       = dto.customer.LastName,
                    Email          = dto.customer.Email,
                    Address        = dto.customer.Address,
                    BillingAddress = dto.customer.BillingAddress,
                    OpenDate       = DateTime.Now
                };
                _context.Customer.Add(newCustomer);

                await _context.SaveChangesAsync();

                var customerId = newCustomer.Id;
                return(Ok(new { id = customerId }));
            }
            catch (Exception ex)
            {
                return(NotFound());
            }
        }
예제 #3
0
        public async Task <IActionResult> PutDCustomer(int id, DCustomer dCustomer)
        {
            dCustomer.Id = id;

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

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

            return(NoContent());
        }
예제 #4
0
 public LCustomer()
 {
     objDCustomer = new DCustomer();
 }