コード例 #1
0
        /// <summary>
        /// Adds a new customer location to the database (location + history)
        /// </summary>
        /// <param name="customerLocationDTO"></param>
        /// <returns>The added Customer</returns>
        public CustomerLocationDTO Create(CustomerLocationDTO customerLocationDTO)
        {
            var clientId = _clientUserService.GetUserClientId(_currentUserId);

            // CustomerLocation
            var customerLocation = AutoMapper.Mapper.Map <CustomerLocation>(customerLocationDTO);

            customerLocation.CreatedByUserId = _currentUserId;
            customerLocation.CreatedDate     = DateTime.UtcNow;
            customerLocation.Status          = Status.Active;

            _unitOfWork.CustomerLocations.Add(customerLocation);
            // Have to call this here to get the new CustomerId
            _unitOfWork.SaveChanges();

            // History
            var customerLocationHistory = AutoMapper.Mapper.Map <CustomerLocationHistory>(customerLocation);

            customerLocationHistory.CustomerLocationId = customerLocation.Id;
            customerLocationHistory.ModifiedByUserId   = _currentUserId;
            customerLocationHistory.ModifiedDate       = customerLocation.CreatedDate;
            customerLocationHistory.Status             = Status.Active;

            _unitOfWork.CustomerLocationsHistory.Add(customerLocationHistory);

            _unitOfWork.SaveChanges();

            return(customerLocationDTO);
        }
コード例 #2
0
        /// <summary>
        /// Updates a Customer Location
        /// </summary>
        /// <param name="id"></param>
        /// <param name="customerLocationDTO"></param>
        /// <returns>The saved customerLocationDTO</returns>
        public CustomerLocationDTO Update(int id, CustomerLocationDTO customerLocationDTO)
        {
            var customerLocation = _unitOfWork.CustomerLocations.Get(id);

            //AutoMapper.Mapper.Map(customerLocationDTO, customerLocation);
            customerLocation.CustomerId      = customerLocationDTO.CustomerId;
            customerLocation.Name            = customerLocationDTO.Name;
            customerLocation.Type            = customerLocationDTO.Type;
            customerLocation.Address1        = customerLocationDTO.Address1;
            customerLocation.Address2        = customerLocationDTO.Address2;
            customerLocation.City            = customerLocationDTO.City;
            customerLocation.Province        = customerLocationDTO.Province;
            customerLocation.PostalCode      = customerLocationDTO.PostalCode;
            customerLocation.Country         = customerLocationDTO.Country;
            customerLocation.CreatedByUserId = _currentUserId;
            _unitOfWork.CustomerLocations.Update(customerLocation);

            // History
            var customerLocationHistory = AutoMapper.Mapper.Map <CustomerLocationHistory>(customerLocation);

            customerLocationHistory.CustomerLocationId = customerLocation.Id;
            customerLocationHistory.ModifiedByUserId   = _currentUserId;
            customerLocationHistory.ModifiedDate       = DateTime.UtcNow;
            customerLocationHistory.Status             = customerLocation.Status;

            _unitOfWork.CustomerLocationsHistory.Add(customerLocationHistory);

            _unitOfWork.SaveChanges();

            return(customerLocationDTO);
        }
コード例 #3
0
        /// <summary>
        /// Returns a CustomerLocationDTO by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public CustomerLocationDTO Get(int id)
        {
            var customerLocationDTO = new CustomerLocationDTO();
            var customerLocation    = _unitOfWork.CustomerLocations.Get(id);

            if (customerLocation != null)
            {
                customerLocationDTO = AutoMapper.Mapper.Map <CustomerLocationDTO>(customerLocation);
            }

            return(customerLocationDTO);
        }
コード例 #4
0
        // GET: CustomerLocations/Create
        public ActionResult Create(int?customerId)
        {
            ViewBag.CountryList      = _mainService.GetCountryDropdownItems();
            ViewBag.ProvinceList     = _mainService.GetProvinceDropdownItems();
            ViewBag.LocationTypeList = _mainService.GetLocationTypeDropdownItems();
            ViewBag.CustomersList    = _mainService.GetCustomerDropdownItems();

            if (customerId.HasValue)
            {
                var customerLocationDTO = new CustomerLocationDTO()
                {
                    CustomerId = (int)customerId,
                };
                return(View(customerLocationDTO));
            }

            return(View());
        }
コード例 #5
0
        public ActionResult Create(CustomerLocationDTO customerLocationDTO)
        {
            ViewBag.CountryList      = _mainService.GetCountryDropdownItems();
            ViewBag.ProvinceList     = _mainService.GetProvinceDropdownItems();
            ViewBag.LocationTypeList = _mainService.GetLocationTypeDropdownItems();
            ViewBag.CustomersList    = _mainService.GetCustomerDropdownItems();

            if (ModelState.IsValid)
            {
                if (customerLocationDTO.Type == LocationType.HeadOffice)
                {
                    if (_customerLocationsService.HasHeadOffice((int)customerLocationDTO.CustomerId))
                    {
                        ModelState.AddModelError("Type", "This customer already has a head office location");
                        return(View(customerLocationDTO));
                    }
                }
                _customerLocationsService.Create(customerLocationDTO);

                return(RedirectToAction("Index"));
            }

            return(View(customerLocationDTO));
        }
コード例 #6
0
        public ActionResult Edit(CustomerLocationDTO customerLocationDTO)
        {
            ViewBag.CountryList      = _mainService.GetCountryDropdownItems();
            ViewBag.ProvinceList     = _mainService.GetProvinceDropdownItems();
            ViewBag.LocationTypeList = _mainService.GetLocationTypeDropdownItems();

            if (ModelState.IsValid)
            {
                if (customerLocationDTO.Type == LocationType.HeadOffice)
                {
                    var headOffice = _customerLocationsService.GetHeadOffice(customerLocationDTO.CustomerId);
                    if (headOffice != null && headOffice.Id != customerLocationDTO.Id)
                    {
                        ModelState.AddModelError("Type", "This customer already has a head office location");
                        return(View(customerLocationDTO));
                    }
                }
                //customerLocationDTO.Customer = _customerService.Get((int)customerLocationDTO.CustomerId);
                _customerLocationsService.Update(customerLocationDTO.Id, customerLocationDTO);

                return(RedirectToAction("Index"));
            }
            return(View(customerLocationDTO));
        }
コード例 #7
0
 public CustomerViewModel()
 {
     CustomerDTO           = new CustomerDTO();
     HeadOfficeLocationDTO = new CustomerLocationDTO();
 }