public void AddCustomerLocation(string customerId, int bookingId, double longitude, double latitude) { var location = new CustomerLocations { Time = DateTimeUtil.GetTimeNow(), CustomerId = customerId, BookingId = bookingId, GpsLat = latitude, GpsLong = longitude }; _locationRepository.Add(location); }
public ActionResult Add(AddCustomerViewModel model) { FillLookups(); string pictureName = ""; if (ModelState.IsValid)// && model.Location.IsValid()) { var newCustomerId = _customerRepository.GetAll().Last().Id + 1; if (!string.IsNullOrWhiteSpace(model.LogoFileName)) { bool isValidPicture; pictureName = GetLabelPath(model.CustomerType == OmsCustomerType.Custom, model.LogoFileName, newCustomerId, out isValidPicture); if (!isValidPicture) { ModelState.AddModelError(string.Empty, pictureName); return(View("Add", model)); } } var user = new User { FirstName = model.OrderContactFirstName, LastName = model.OrderContactLastName, Email = model.OrderContactEmail, Phone = model.OrderContactPhone, Password = model.PortalPassword, IsActive = true, TypeId = 2 }; _userRepository.Add(user); _userRepository.Save(); var customer = new Customer { BestBeforeDays = model.BestBeforeDays, LogoTypeId = model.UseLogoOnLabels, LogoFileName = pictureName, Name = model.CustomerName, CustomerTypeId = model.CustomerType, PONumber = model.CustomerPo, DistributedBy = model.LabelDistributedBy, BoxLabel = model.BoxLabel, TrayLabel = model.TrayLabel, BagLabel = model.BagLabel, User = user, IsArchived = model.IsArchived, UserId = user.Id }; _customerRepository.Add(customer); _customerRepository.Save(); var products = _productRepository.GetByCustomerType(model.CustomerType).Where(x => x.IsActive).ToList(); var customerProducts = new List <CustomerProductData>(); foreach (var product in products) { customerProducts.Add(new CustomerProductData { CustomerId = customer.Id, ProductId = product.Id, ProductCode = product.Code, ProductDescription = product.EnglishDescription, Gtin = product.Gtin, PricePerPound = product.PricePerPound }); } _customerProductDataRepository.AddRange(customerProducts); _customerProductDataRepository.Save(); if (model.Location.IsExists()) { var location = model.Location.ToCustomerLocation(); location.CustomerId = customer.Id; _customerLocationRepository.Add(location); _customerLocationRepository.Save(); } return(RedirectToAction("EditCustomer", new { customerId = customer.Id })); } foreach (var pair in model.Location.Validate()) { ModelState.AddModelError(pair.Key, pair.Value); } return(View(model)); }