Exemplo n.º 1
0
        public ActionResult RateUpdate(ByTotalModel model, GridCommand command)
        {
            if (!ModelState.IsValid)
            {
                return new JsonResult { Data = "error" };
            }

            var shippingByTotalRecord = _shippingByTotalService.GetShippingByTotalRecordById(model.Id);
            shippingByTotalRecord.Zip = model.Zip == "*" ? null : model.Zip;
            shippingByTotalRecord.From = model.From;
            shippingByTotalRecord.To = model.To;
            shippingByTotalRecord.UsePercentage = model.UsePercentage;
            shippingByTotalRecord.ShippingChargeAmount = model.ShippingChargeAmount;
            shippingByTotalRecord.ShippingChargePercentage = model.ShippingChargePercentage;
            shippingByTotalRecord.BaseCharge = model.BaseCharge;
            shippingByTotalRecord.MaxCharge = model.MaxCharge;
            _shippingByTotalService.UpdateShippingByTotalRecord(shippingByTotalRecord);

            return RatesList(command);
        }
		/// <summary>
		/// Get models for shipping by total records
		/// </summary>
		public virtual IList<ByTotalModel> GetShippingByTotalModels(int pageIndex, int pageSize, out int totalCount)
		{
			// data join would be much better but not possible here cause ShippingByTotalObjectContext cannot be shared across repositories
			var records = GetShippingByTotalRecords(pageIndex, pageSize);
			totalCount = records.TotalCount;

			if (records.Count <= 0)
				return new List<ByTotalModel>();

			var allStores = _storeService.GetAllStores();

			var result = records.Select(x =>
				{
					var store = allStores.FirstOrDefault(y => y.Id == x.StoreId);
					var shippingMethod = _shippingService.GetShippingMethodById(x.ShippingMethodId);
					var country = _countryService.GetCountryById(x.CountryId ?? 0);
					var stateProvince = _stateProvinceService.GetStateProvinceById(x.StateProvinceId ?? 0);

					var model = new ByTotalModel()
					{
						Id = x.Id,
						StoreId = x.StoreId,
						ShippingMethodId = x.ShippingMethodId,
						CountryId = x.CountryId,
						StateProvinceId = x.StateProvinceId,
						Zip = (x.Zip.HasValue() ? x.Zip : "*"),
						From = x.From,
						To = x.To,
						UsePercentage = x.UsePercentage,
						ShippingChargePercentage = x.ShippingChargePercentage,
						ShippingChargeAmount = x.ShippingChargeAmount,
						BaseCharge = x.BaseCharge,
						MaxCharge = x.MaxCharge,
						StoreName = (store == null ? "*" : store.Name),
						ShippingMethodName = (shippingMethod == null ? "".NaIfEmpty() : shippingMethod.Name),
						CountryName = (country == null ? "*" : country.Name),
						StateProvinceName = (stateProvince ==null ? "*" : stateProvince.Name)
					};

					return model;
				})
				.ToList();

			return result;
		}