Example #1
0
        public List <CustomerLocationModel> BuildCustomerLocationModels(List <CustomerLocation> customerLocations)
        {
            var list = new List <CustomerLocationModel>();

            foreach (var item in customerLocations)
            {
                var model = new CustomerLocationModel();
                model.CustomerLocationID   = item.CustomerLocationID;
                model.CustomerLocationName = item.CustomerLocationName;
                model.CustomerID           = item.CustomerID;
                model.Telephone            = item.TelephoneNumber;
                model.FaxNumber            = item.FaxNumber;
                // get Address object
                item.Address       = _addressService.AddressById(item.AddressID);
                model.AddressID    = item.Address.AddressID;
                model.AddressLine1 = item.Address.AddressLine1;
                model.AddressLine2 = item.Address.AddressLine2;
                model.AddressLine3 = item.Address.AddressLine3;
                model.Postcode     = item.Address.Postcode;
                model.PostalTown   = item.Address.PostalTown;
                model.CountyCity   = item.Address.CountyCity;
                // Notes
                model.NoteID = item.NoteID;
                model.Notes  = item.NoteID.HasValue ? _noteService.Find(item.NoteID.Value).NoteText : string.Empty;
                list.Add(model);
            }
            return(list);
        }
Example #2
0
 public CustomerLocationModel CreateCustomerLocation(CustomerLocationModel model)
 {
     try
     {
         var item = ApplyChanges(model);
         item.NoteID    = SaveNote(model);
         item.AddressID = SaveAddr(model, item.Address);
         if (model.CustomerLocationID == Guid.Empty &&
             model.ItemAdding && !model.ItemDeleting)
         {
             model.CustomerLocationID = PrimeActs.Service.IDGenerator.NewGuid(_serverCode[0]);
             item.CustomerLocationID  = model.CustomerLocationID;
             item.ObjectState         = ObjectState.Added;
             _locationService.Insert(item);
         }
         else if (!model.ItemAdding && !model.ItemDeleting)
         {
             item.ObjectState = ObjectState.Modified;
             _locationService.Update(item);
         }
     }
     catch (Exception ex)
     {
         throw new ApplicationException("Creating Supplier Location failed", ex);
     }
     return(model);
 }
        private void cmbSites_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbSites.SelectedItem as CustomerLocationModel != null)
            {
                objCustomerLocationModel = cmbSites.SelectedItem as CustomerLocationModel;

                addImageToMap(CustomerSiteMap, null);
            }
        }
Example #4
0
        private Guid UpdateNote(CustomerLocationModel model)
        {
            var note = _noteService.Find(model.NoteID.Value);

            note.NoteText        = model.Notes;
            note.NoteDescription = model.NoteDescription;
            note.ObjectState     = ObjectState.Modified;
            _noteService.Update(note);
            return(note.NoteID);
        }
Example #5
0
        private Guid CreateNote(CustomerLocationModel model)
        {
            var note = new Note
            {
                NoteID          = PrimeActs.Service.IDGenerator.NewGuid(_serverCode[0]),
                NoteText        = model.Notes,
                NoteDescription = model.NoteDescription,
                ObjectState     = ObjectState.Added
            };

            _noteService.Insert(note);
            return(note.NoteID);
        }
Example #6
0
 private void cmbSites_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (cmbSites.SelectedItem as CustomerLocationModel != null)
     {
         objCustomerLocationModel = cmbSites.SelectedItem as CustomerLocationModel;
         Location location = new Location()
         {
             Latitude = Convert.ToDouble(objCustomerLocationModel.Location.Latitude), Longitude = Convert.ToDouble(objCustomerLocationModel.Location.Longitude)
         };
         CustomerSiteMap.Children.Cast <Microsoft.Maps.MapControl.WPF.Pushpin>().FirstOrDefault().Location = location;
         CustomerSiteMap.Center = location;
         //addImageToMap(CustomerSiteMap, null);
     }
 }
Example #7
0
        private Guid UpdateAddr(CustomerLocationModel model, Address address)
        {
            var addr = _addressService.Find(model.AddressID);

            addr.AddressLine1 = model.AddressLine1;
            addr.AddressLine2 = model.AddressLine2;
            addr.AddressLine3 = model.AddressLine3;
            addr.PostalTown   = model.PostalTown;
            addr.CountyCity   = model.CountyCity;
            addr.Postcode     = model.Postcode;
            addr.ObjectState  = ObjectState.Modified;
            address           = addr;
            _addressService.Update(addr);
            return(addr.AddressID);
        }
 public TResponse GetAll()
 {
     using (var db = new UnitOfWork())
     {
         try
         {
             List <CustomerLocationModel> lstCustomerLocationModel = new List <CustomerLocationModel>();
             CustomerLocationModel        objCustomerLocationModel;
             List <CustomerLocation>      lstCustomerLocation = db.CustomerLocationRepository.Get().ToList();
             if (lstCustomerLocation != null && lstCustomerLocation.Count > 0)
             {
                 foreach (CustomerLocation objCustomerLocation in lstCustomerLocation)
                 {
                     objCustomerLocationModel              = new CustomerLocationModel();
                     objCustomerLocationModel.ID           = objCustomerLocation.ID;
                     objCustomerLocationModel.CustomerID   = Convert.ToInt64(objCustomerLocation.CustomerID);
                     objCustomerLocationModel.CustomerName = objCustomerLocation.UserProfile.FName + " " + objCustomerLocation.UserProfile.LName;
                     objCustomerLocationModel.Location     = objCustomerLocation.Location;
                     objCustomerLocationModel.LocationName = objCustomerLocation.LocationName;
                     objCustomerLocationModel.IsActive     = Convert.ToBoolean(objCustomerLocation.IsActive);
                     objCustomerLocationModel.IsDeleted    = Convert.ToBoolean(objCustomerLocation.IsDeleted);
                     objCustomerLocationModel.CreatedOn    = Convert.ToDateTime(objCustomerLocation.CreatedOn);
                     objCustomerLocationModel.UpdatedOn    = Convert.ToDateTime(objCustomerLocation.UpdatedOn);
                     objCustomerLocationModel.UpdatedOn    = Convert.ToDateTime(objCustomerLocation.UpdatedOn);
                     lstCustomerLocationModel.Add(objCustomerLocationModel);
                 }
                 objTResponse.Status         = ResponseStaus.ok;
                 objTResponse.Message        = ResponseMessage.success;
                 objTResponse.ResponsePacket = lstCustomerLocationModel;
             }
             else
             {
                 objTResponse.Status         = ResponseStaus.error;
                 objTResponse.Message        = ResponseMessage.ItemNotFound;
                 objTResponse.ResponsePacket = null;
             }
             return(objTResponse);
         }
         catch (DbEntityValidationException dbEx)
         {
             ErrorLogBusiness objerrorlog = new ErrorLogBusiness();
             objerrorlog.AddErrorLog(new ErrorLogModel {
                 MethodName = "ListCustomerLocation", Id = 0, ClassName = "CustomerLocationBusiness", Error = dbEx.Message
             });
             return(objTResponse);
         }
     }
 }
Example #9
0
        private Guid CreateAddr(CustomerLocationModel model, Address address)
        {
            var addr = new Address
            {
                AddressID    = PrimeActs.Service.IDGenerator.NewGuid(_serverCode[0]),
                AddressLine1 = model.AddressLine1,
                AddressLine2 = model.AddressLine2,
                AddressLine3 = model.AddressLine3,
                PostalTown   = model.PostalTown,
                CountyCity   = model.CountyCity,
                Postcode     = model.Postcode,
                ObjectState  = ObjectState.Added
            };

            address = addr;
            _addressService.Insert(addr);
            return(addr.AddressID);
        }
Example #10
0
 private Guid SaveAddr(CustomerLocationModel model, Address address)
 {
     if (!string.IsNullOrEmpty(model.AddressLine1)
         //&& !string.IsNullOrEmpty(model.CountyCity)
         && !string.IsNullOrEmpty(model.PostalTown) &&
         !string.IsNullOrEmpty(model.Postcode))
     {
         if (model.AddressID == null || model.AddressID == Guid.Empty)
         {
             model.AddressID = CreateAddr(model, address);
         }
         else
         {
             model.AddressID = UpdateAddr(model, address);
         }
     }
     return(model.AddressID);
 }
Example #11
0
        private CustomerLocation ApplyChanges(CustomerLocationModel model)
        {
            var cl = new CustomerLocation();

            cl.CustomerLocationID   = model.CustomerLocationID;
            cl.CustomerLocationName = model.CustomerLocationName;
            cl.CustomerID           = model.CustomerID;
            cl.TelephoneNumber      = model.Telephone;
            cl.FaxNumber            = model.FaxNumber;
            cl.CreatedDate          = !string.IsNullOrEmpty(model.CreatedDate)
                ? DateTime.Parse(model.CreatedDate)
                : DateTime.Now;
            cl.CreatedBy   = _principal.Id;
            cl.UpdatedDate = DateTime.Now;
            cl.UpdatedBy   = _principal.Id;
            cl.IsActive    = true;
            return(cl);
        }
Example #12
0
 private Guid?SaveNote(CustomerLocationModel model)
 {
     if (string.IsNullOrEmpty(model.NoteDescription))
     {
         model.NoteDescription = "?!";  // <--- Paul Edwards
     }
     if (!string.IsNullOrEmpty(model.Notes))
     {
         if (model.NoteID == null || model.NoteID == Guid.Empty)
         {
             model.NoteID = CreateNote(model);
         }
         else
         {
             model.NoteID = UpdateNote(model);
         }
     }
     return(model.NoteID);
 }
        public TResponse GetByID(long Id)
        {
            using (var db = new UnitOfWork())
            {
                try
                {
                    CustomerLocationModel objCustomerLocationModel = new CustomerLocationModel();
                    CustomerLocation      objCustomerLocation      = db.CustomerLocationRepository.Get(x => x.ID == Id).FirstOrDefault();
                    if (objCustomerLocation != null)
                    {
                        objCustomerLocationModel.ID           = objCustomerLocation.ID;
                        objCustomerLocationModel.CustomerID   = Convert.ToInt64(objCustomerLocation.CustomerID);
                        objCustomerLocationModel.CustomerName = objCustomerLocation.UserProfile.FName + " " + objCustomerLocation.UserProfile.FName;
                        objCustomerLocationModel.Location     = objCustomerLocation.Location;
                        objCustomerLocationModel.LocationName = objCustomerLocation.LocationName;
                        objCustomerLocationModel.IsActive     = Convert.ToBoolean(objCustomerLocation.IsActive);
                        objCustomerLocationModel.IsDeleted    = Convert.ToBoolean(objCustomerLocation.IsDeleted);
                        objCustomerLocationModel.CreatedOn    = Convert.ToDateTime(objCustomerLocation.CreatedOn);
                        objCustomerLocationModel.UpdatedOn    = Convert.ToDateTime(objCustomerLocation.UpdatedOn);

                        objTResponse.Status         = ResponseStaus.ok;
                        objTResponse.Message        = ResponseMessage.success;
                        objTResponse.ResponsePacket = objCustomerLocationModel;
                    }
                    else
                    {
                        objTResponse.Status         = ResponseStaus.error;
                        objTResponse.Message        = ResponseMessage.ItemNotFound;
                        objTResponse.ResponsePacket = null;
                    }
                    return(objTResponse);
                }
                catch (DbEntityValidationException dbEx)
                {
                    ErrorLogBusiness objerrorlog = new ErrorLogBusiness();
                    objerrorlog.AddErrorLog(new ErrorLogModel {
                        MethodName = "GetByID", Id = Id, ClassName = "CustomerLocationBusiness", Error = dbEx.Message
                    });
                    return(objTResponse);
                }
            }
        }
 public ActionResult AddUpdate(CustomerLocationModel objCustomerLocationModel)
 {
     objTResponse = new CustomerLocationBusiness().AddUpdate(objCustomerLocationModel);
     return(RedirectToAction("List"));
 }