/// <summary> /// Add a new record /// </summary> /// <returns>Service response <Customer></Customer></returns> public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { _db.Customers.Add(customer); _db.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { IsSuccess = true, Message = "New customer added", Time = DateTime.UtcNow, Data = customer }); }catch (Exception) { return(new ServiceResponse <Data.Models.Customer> { IsSuccess = false, Message = "Failed to add customer", Time = DateTime.UtcNow, Data = customer }); } }
/// <summary> /// Create a new customer /// </summary> /// <param name="customer"></param> /// <returns></returns> public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { _db.Customers.Add(customer); _db.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { IsSuccess = true, Message = "Add New Customer", Data = customer, Time = DateTime.UtcNow, }); } catch (Exception e) { return(new ServiceResponse <Data.Models.Customer> { IsSuccess = false, Message = e.Message, Data = null, Time = DateTime.UtcNow, }); } }
/// <summary> /// Adds a new Customer record /// </summary> /// <param name="customer">Customer instance</param> /// <returns>ServiceResponse<Customer></returns> ServiceResponse <Data.Models.Customer> ICustomerService.CreateCustomer(Data.Models.Customer customer) { try { _db.Customers.Add(customer); _db.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { IsSuccess = true, Data = customer, Message = "Customer was added", Time = DateTime.UtcNow }); } catch (Exception ex) { return(new ServiceResponse <Data.Models.Customer> { IsSuccess = false, Data = customer, Message = ex.StackTrace, Time = DateTime.UtcNow }); } }
public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { customer.CreatedDate = DateTime.Now; customer.UpdatedDate = DateTime.Now; customer.PrimaryAddress.CreatedDate = DateTime.Now; customer.PrimaryAddress.UpdatedDate = DateTime.Now; _db.Customers.Add(customer); _db.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { Data = customer, IsSuccess = true, Message = "created Successfully", Time = DateTime.UtcNow }); } catch (Exception ex) { return(new ServiceResponse <Data.Models.Customer> { Data = null, IsSuccess = false, Message = ex.StackTrace, Time = DateTime.UtcNow }); } }
public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { _context.Customers.Add(customer); _context.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { IsSuccess = true, Message = "New Customer Added", Time = DateTime.UtcNow, Data = customer }); } catch (Exception ex) { return(new ServiceResponse <Data.Models.Customer> { IsSuccess = false, Message = $"New Customer Added: {ex.Message} - {ex.StackTrace} ", Time = DateTime.UtcNow, Data = customer }); } }
private IResult <Data.Models.Customer> SetCustomerBroker(Data.Models.Customer customer, CompanyKey brokerKey) { if (customer == null) { throw new ArgumentNullException("customer"); } Data.Models.Company broker; if (brokerKey == null) { broker = CompanyUnitOfWork.CompanyRepository.Filter(c => c.Name == StaticCompanies.RVCBroker.Name).FirstOrDefault(); if (broker == null) { throw new Exception("Default RVC Broker Company not found."); } } else { var brokerResult = new GetCompanyCommand(CompanyUnitOfWork).Execute(brokerKey, CompanyType.Broker); if (!brokerResult.Success) { return(brokerResult.ConvertTo <Data.Models.Customer>()); } broker = brokerResult.ResultingObject; } customer.BrokerId = broker.Id; return(new SuccessResult <Data.Models.Customer>(customer)); }
public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { _dbContext.Customers.Add(customer); _dbContext.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { IsSuccess = true, Message = "New customer added", Time = DateTime.UtcNow, Data = customer }); } catch (Exception ex) { return(new ServiceResponse <Data.Models.Customer> { IsSuccess = false, Message = $"Failed to add a new customer with the following error: {ex}", Time = DateTime.UtcNow, Data = customer }); } }
public ActionResult SignIn(FormCollection f)//; Data.Models.Login account) { //if (String.IsNullOrEmpty(account.Email)) //{ // ModelState.AddModelError(nameof(account.Email), "Email is required"); //yeu cau nhap email //} //if (String.IsNullOrEmpty(account.PassWord)) //{ // ModelState.AddModelError(nameof(account.PassWord), "Password is required"); //yeu cau nhap email //} // FormCollection f = new FormCollection(); string sodienthoai = f["SDT"]; string matkhau = f["password"]; Data.Models.Customer us = bhx.Customers.SingleOrDefault(n => n.PhoneNumber == sodienthoai && n.Password == matkhau); if (us != null) { return(Content("/Main/Index")); } else { var us1 = (from u in bhx.Employees where u.Password == matkhau && u.PhoneNumber == sodienthoai select u).SingleOrDefault();// FirstOrDefault(); if (us1 != null) { return(Content("/Products/Drinks")); } } return(Content("false")); // return View(); }
public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { _db.Customers.Add(customer); _db.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { Data = customer, Time = DateTime.UtcNow, IsSuccess = true, Message = "Successfully added customer" }); } catch (Exception e) { return(new ServiceResponse <Data.Models.Customer> { Data = null, Time = DateTime.UtcNow, IsSuccess = false, Message = "Error adding Customer" + e.StackTrace }); } }
/// <summary> /// Add a new Customer record /// </summary> /// <param name="id">Customer instance</param> /// <returns>ServiceResponse<Customer></returns> public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { _db.CustomersAddresses.Add(customer.PrimaryAddress); _db.Customers.Add(customer); _db.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { IsSuccess = true, Message = "New customer added", Time = DateTime.UtcNow, Data = customer }); } catch (Exception e) { return(new ServiceResponse <Data.Models.Customer> { IsSuccess = false, Message = e.StackTrace, Time = DateTime.UtcNow, Data = customer }); } }
public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { var now = DateTime.UtcNow; try { _db.Customers.Add(customer); _db.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { Time = now, IsSuccess = true, Message = "Customer created successfully!", Data = customer }); } catch (Exception e) { return(new ServiceResponse <Data.Models.Customer> { Time = now, IsSuccess = false, Message = e.StackTrace, Data = customer }); } }
/// <summary> /// create a new customer; criando cliente /// </summary> /// <param name="customer"></param> /// <returns></returns> public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { _db.Customers.Add(customer); _db.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { IsSucess = true, Message = " New record add", Time = DateTime.Now, Data = customer }); } catch (Exception ex) { return(new ServiceResponse <Data.Models.Customer> { IsSucess = false, Message = ex.StackTrace, Time = DateTime.Now, Data = customer }); throw; } }
/// <summary> /// Create a new Customer /// </summary> /// <param name="customer"></param> /// <returns></returns> public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { _db.Customers.Add(customer); _db.SaveChanges(); return(new ServiceResponse <Data.Models.Customer> { Data = customer, Time = DateTime.UtcNow, Message = "Created new customer", IsSuccess = true }); } catch (Exception e) { return(new ServiceResponse <Data.Models.Customer> { Data = customer, Time = DateTime.UtcNow, Message = e.StackTrace, IsSuccess = false }); } }
//public ICollection<Order> orders //{ // get; // set; //} internal static Customer ToViewModel(Data.Models.Customer customer) { return(new Customer() { Id = customer.Id, Address = customer.Address, FirstName = customer.FirstName, LastName = customer.LastName, Phone = customer.Phone }); }
public CustomerEdit(Data.Models.Customer customer) { _customer = customer ?? new Data.Models.Customer(); if (customer != null && customer.Id != 0) { Id = customer.Id; } Name = customer.Name; Surname = customer.Surname; Phone = customer.Phone; Email = customer.Email; AddressEdit = new AddressEdit(customer.Address); }
public Customer(Data.Models.Customer customer) { Id = customer.Id; Name = customer.Name; IsDeactivated = customer.IsDeactivated; CreatedDate = customer.CreatedDate; LastModifiedDate = customer.LastModifiedDate; if (customer.Projects != null) { Projects = customer.Projects.Select(x => new Project(x)); } }
public void AddCustomer_AddsCustomerToContextWithGeneratedId() { //arrange var request = _fixture.Create <AddCustomerRequest>(); var expected = new Data.Models.Customer { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email, Created = DateTime.UtcNow }; //act _customerService.AddCustomer(request); //assert _databaseContext.Customer.Should().ContainEquivalentOf(expected, options => options .Excluding(patient => patient.Id) .Excluding(patient => patient.Created) ); }
public ServiceResponse <Data.Models.Customer> CreateCustomer(Data.Models.Customer customer) { try { return(new ServiceResponse <Data.Models.Customer> { IsSuccess = true, Message = "New Customer Added", Time = DateTime.UtcNow, Data = customer }); } catch (Exception e) { return(new ServiceResponse <Data.Models.Customer> { IsSuccess = false, Message = e.StackTrace, Time = DateTime.UtcNow, Data = customer }); } }
/// <summary> /// Map to database model from service model /// </summary> /// <param name="from"></param> /// <param name="includeDeps"></param> /// <returns></returns> public static Data.Models.Customer MapBack(Customer from, bool includeDeps = true) { if (from == null) { return(null); } var dto = new Data.Models.Customer() { Id = from.Id, Name = from.Name, Email = from.Email, }; if (includeDeps) { if (from.Orders != null) { dto.Orders = from.Orders.Select(x => OrderMap.MapBack(x, false)).ToArray(); } } return(dto); }
public void Create(Data.Models.Customer customer) { dbContext.Customer.Add(customer); dbContext.SaveChanges(); }
public Customer Get(Guid id) { Data.Models.Customer foundCustomer = CustomerRepository.Get(id); return(new Customer(foundCustomer)); }