コード例 #1
0
        public async Task<ResponseBool> OutletUpdateAsync(OutletItem outletItem)
        {
            ResponseBool _response = new ResponseBool { Success = false, ErrorInfo = "" };
            string url = string.Format("api/distributorservices/outletupdate");
            var httpClient = setupHttpClient();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            try
            {
                var response = await httpClient.PostAsJsonAsync(url, outletItem);
                _response = await response.Content.ReadAsAsync<ResponseBool>();
            }
            catch (Exception ex)
            {
                _response.ErrorInfo = "Error: An error occurred when updating the outlet.\nCause: " + ex.Message;
                _log.Error("Failed to update outlet", ex);
            }

            return _response;
        }
コード例 #2
0
       async void DoSave()
        {
            if (!IsValid())
                return;
            using (StructureMap.IContainer c = NestedContainer)
            {
                ResponseBool response = null;
                var proxy = Using<IDistributorServiceProxy>(c);

                var shippingAddresses = this.ShippingAddresses.Select(address => new ShipToAddress
                                                                                     {
                                                                                         MasterId = address.Id,
                                                                                         Name = address.Name ?? "",
                                                                                         PhysicalAddress =
                                                                                             address.PhysicalAddress ??
                                                                                             "",
                                                                                         PostalAddress =
                                                                                             address.PostalAddress ?? "",
                                                                                         Longitude =
                                                                                             address.AddressLongitude,
                                                                                         Latitude =
                                                                                             address.AddressLatitude,
                                                                                         Description =
                                                                                             address.Description ?? "",
                                                                                     }).ToList();
                shippingAddresses.AddRange(DeletedAddresses);
                if (Id == Guid.Empty)
                {
                    try
                    {
                       
                        OutletItem item = new OutletItem
                                              {
                                                  MasterId = Guid.NewGuid(),
                                                  Name = Name,
                                                  OutletCategoryMasterId = SelectedOutletCategory.Id,
                                                  OutletTypeMasterId = SelectedOutletType.Id,
                                                  RouteMasterId = SelectedRoute.Id,
                                                  StatusId =(int)EntityStatus.Active ,
                                                  CostCentreTypeId = (int) CostCentreType.Outlet,
                                                  DateCreated = DateTime.Now,
                                                  DateLastUpdated = DateTime.Now,
                                                  ParentCostCentreId = Using<IConfigService>(c).Load().CostCentreId,
                                                  OutletProductPricingTierMasterId =
                                                      SelectedProductPricingTier.Id,
                                                  OutletVATClassMasterId =  SelectedVATRate.Id,
                                                  OutletDiscountGroupMasterId = SelectedDiscountGroup.Id,
                                                  outLetCode = OutletCode,
                                                  Latitude = Latitude,
                                                  Longitude = Longitude,
                                                  ShippingAddresses = shippingAddresses
                                              };
                        response = await proxy.OutletAddAsync(item);

                        AuditLogEntry = string.Format("Created New Outlet: {0}; OutletType: {1}; Route: {2}; Tier{3};", Name,
                                                 SelectedOutletType.Name, SelectedRoute.Name,
                                                 SelectedProductPricingTier.Name);
                        Using<IAuditLogWFManager>(c).AuditLogEntry("Outlets Administration", AuditLogEntry);

                    }catch(Exception e)
                    {
                        MessageBox.Show(e.Message, "Distributr", MessageBoxButton.OK);
                    }
                    
                   
                }
                else
                {
                   
                   response= await proxy.OutletUpdateAsync(new OutletItem
                            {
                                MasterId = Id,
                                Name = Name,
                                OutletCategoryMasterId = SelectedOutletCategory.Id,
                                OutletTypeMasterId = SelectedOutletType.Id,
                                RouteMasterId = SelectedRoute.Id,
                                StatusId = IsApproved
                                               ? (int) EntityStatus.Active
                                               : (int) EntityStatus.New,
                                CostCentreTypeId = (int) CostCentreType.Outlet,
                                DateCreated = DateTime.Now,
                                DateLastUpdated = DateTime.Now,
                                ParentCostCentreId = Using<IConfigService>(c).Load().CostCentreId,
                                OutletProductPricingTierMasterId = SelectedProductPricingTier.Id,
                                OutletVATClassMasterId =  SelectedVATRate.Id,
                                OutletDiscountGroupMasterId = SelectedDiscountGroup.Id,
                                outLetCode = OutletCode,
                                Latitude = Latitude,
                                Longitude = Longitude,
                                ShippingAddresses = shippingAddresses
                            });
                    AuditLogEntry = string.Format("Updated Outlet: {0}; OutletType: {1}; Route: {2}; Tier{3};", Name,
                                                  SelectedOutletType.Name, SelectedRoute.Name,
                                                  SelectedProductPricingTier.Name);
                    Using<IAuditLogWFManager>(c).AuditLogEntry("Outlets Administration", AuditLogEntry);
                }
                MessageBox.Show(response.ErrorInfo, "Distributr:", MessageBoxButton.OK);
                if (response.Success)
                {
                    ConfirmNavigatingAway = false;
                    SendNavigationRequestMessage(new Uri("views/administration/outlets/listoutlets.xaml",
                                                         UriKind.Relative));
                }
            }
            AddressName = "";
            PhysicalAddress = "";
            PostalAddress = "";
            AddressLongitude = 0;
            AddressLatitude = 0;
            AddressDescription = "";
        }
コード例 #3
0
        public HttpResponseMessage OutletUpdate(OutletItem outletItem)
        {
            var response = new ResponseBool { Success = false };
            try
            {
                Outlet outlet = _outletRepository.GetById(outletItem.MasterId) as Outlet;
                outlet.Route = _routeRepository.GetById(outletItem.RouteMasterId);
                outlet.Name = outletItem.Name;
                outlet.OutletCategory = _outletCategoryRepository.GetById(outletItem.OutletCategoryMasterId);
                outlet.OutletType = _outletTypeRepository.GetById(outletItem.OutletTypeMasterId);
                outlet.OutletProductPricingTier =
                    _productPricingTierRepository.GetById(outletItem.OutletProductPricingTierMasterId);
                outlet.CostCentreCode = outletItem.outLetCode;
                outlet.CostCentreCode = outletItem.outLetCode;
                outlet.Latitude = outletItem.Latitude;
                outlet.Longitude = outletItem.Longitude;
                outlet._Status = (EntityStatus)outletItem.StatusId;
                outlet.ShipToAddresses.Clear();
                foreach (var address in outletItem.ShippingAddresses)
                {
                    var shipToAddress = new ShipToAddress(address.MasterId)
                    {
                        Name = address.Name,
                        PhysicalAddress = address.PhysicalAddress,
                        PostalAddress = address.PostalAddress,
                        Longitude = address.Longitude ?? 0,
                        Latitude = address.Latitude ?? 0,
                        Description = address.Description,
                        _Status = (EntityStatus)address.EntityStatus,

                    };
                    outlet.AddShipToAddress(shipToAddress);
                }
                try
                {
                    outlet.VatClass = _vatClassRepository.GetById(outletItem.OutletVATClassMasterId);
                }
                catch //cn: VATClass is removed or some other error
                {
                    outlet.VatClass = null;
                }
                try
                {
                    outlet.DiscountGroup = _discountGroupRepository.GetById(outletItem.OutletDiscountGroupMasterId);
                }
                catch //cn: VATClass is removed or some other error
                {
                    outlet.DiscountGroup = null;
                }

                _costCentreRepository.Save(outlet);
                response.Success = true;
                response.ErrorInfo = "Successfully updated outlet " + outlet.Name;
            }
            catch (DomainValidationException dve)
            {
                string errorMsg = dve.ValidationResults.Results.Aggregate("Error: Invalid outlet fields.\n",
                                                                          (current, msg) =>
                                                                          current + ("\t- " + msg.ErrorMessage + ".\n"));
                response.ErrorInfo = errorMsg;
                _log.Error(errorMsg, dve);
            }
            catch (Exception ex)
            {
                response.ErrorInfo = "Error: An error occurred when updating the outlet.";
                _log.Error("Error: An error occurred when updating the outlet.", ex);
            }
            return Request.CreateResponse(HttpStatusCode.OK, response);

        }