/*
         * CRUD
         */
        public void Register(Freight freight)
        {
            List <Freight> list;

            if (_cookie.isExisting(Key))
            {
                list = Consult();
                var freightLocalized = list.SingleOrDefault(i => i.CEP == freight.CEP);
                if (freightLocalized == null)
                {
                    list.Add(freight);
                }
                else
                {
                    freightLocalized.ShoppingCartCode = freight.ShoppingCartCode;
                    freightLocalized.ListValues       = freight.ListValues;
                }
            }
            else
            {
                list = new List <Freight>();
                list.Add(freight);
            }

            Save(list);
        }
Beispiel #2
0
        public override async Task <FreightModel> GetFreight(GetFreightRequest request, ServerCallContext context)
        {
            GetFreightByIdQuery query = new GetFreightByIdQuery {
                Id = Guid.Parse(request.FreightId)
            };
            Freight freight = await _mediator.Send(query);

            FreightModel response;

            if (freight != null)
            {
                response = new FreightModel
                {
                    Width       = freight.Width,
                    Height      = freight.Height,
                    Length      = freight.Length,
                    FreightType = Protos.FreightType.FullTruckLoad,
                    Weight      = freight.Weight,
                    CreateDate  = Timestamp.FromDateTime(freight.CreateDate)
                };
            }
            else
            {
                response = new FreightModel();
            }
            return(await Task.FromResult(response));
        }
Beispiel #3
0
        // PUT api/values/5
        public Object Put(int id, [FromBody] string freight)
        {
            Freight u = JsonConvert.DeserializeObject <Freight>(freight);

            u.ID = id;
            return(new { success = FreightBLL.UpdateFreight(u) });
        }
        protected bool UnstoreSorting()
        {
            Freight frg = null;

            bool Success = false;

            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                try
                {
                    frg = Freight.SelectFreightByFreightId(CurrentWeighingId, ControlObjectContext);
                    frg.FreightStatus = "In sorting";

                    // and save to persistent storage
                    ControlObjectContext.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave);

                    // commit the transaciton
                    TS.Complete();
                    Success = true;
                }
                catch (Exception ex) // commit or procedure failed somewhere
                {
                    // rollback transaction
                    TS.Dispose();

                    // inform user
                    Common.InformUserOnTransactionFail(ex, Page);
                }
            }
            return(Success);
        }
Beispiel #5
0
        public ActionResult CreateFreight(FreightModel FreightModel1)
        {
            if (ModelState.IsValid)
            {
                FreightModel1.UserId     = User1.Id;
                FreightModel1.CreateDate = DateTime.Now.ToString("dd/MM/yyyy");
                FreightModel1.UpdateDate = DateTime.Now.ToString("dd/MM/yyyy");

                if (FreightModel.FreightTypes.OceanFreight.ToString().Equals(FreightModel1.Type))
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.SeaInbound.ToString();
                }
                else if (FreightModel.FreightTypes.AirFreight.ToString().Equals(FreightModel1.Type))
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.AirInbound.ToString();
                }
                else if (FreightModel.FreightTypes.InlandRates.ToString().Equals(FreightModel1.Type))
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.InlandService.ToString();
                }
                else
                {
                    FreightModel1.ServiceName = ShipmentModel.Services.Other.ToString();
                }
                FreightModel1.ServiceId = servicesType.GetId(FreightModel1.ServiceName);
                Freight Freight1 = _freightService.CreateFreight(FreightModel1);
                if (Freight1 != null)
                {
                    foreach (string inputTagName in Request.Files)
                    {
                        HttpPostedFileBase file = Request.Files[inputTagName];
                        if (file.ContentLength > 0)
                        {
                            string filePath = Path.Combine(Server.MapPath("~/" + FREIGHT_PATH)
                                                           , Path.GetFileName(file.FileName));
                            file.SaveAs(filePath);
                            //save file to db
                            ServerFile ServerFile1 = new ServerFile();
                            ServerFile1.ObjectId     = Freight1.Id;
                            ServerFile1.ObjectType   = Freight1.GetType().ToString();
                            ServerFile1.Path         = FREIGHT_PATH + "/" + file.FileName;
                            ServerFile1.FileName     = file.FileName;
                            ServerFile1.FileSize     = file.ContentLength;
                            ServerFile1.FileMimeType = file.ContentType;
                            _freightService.insertServerFile(ServerFile1);
                        }
                    }
                }
                return(RedirectToAction("ListFreight", new { Id = 0, FreightType = FreightModel1.Type }));
            }
            else
            {
                IEnumerable <Area> AreaListDep = _shipmentService.getAllAreaByCountry(FreightModel1.CountryNameDep);
                IEnumerable <Area> AreaListDes = _shipmentService.getAllAreaByCountry(FreightModel1.CountryNameDes);
                ViewData["AreaListDep"]  = new SelectList(AreaListDep, "Id", "AreaAddress");
                ViewData["AreaListDes"]  = new SelectList(AreaListDes, "Id", "AreaAddress");
                ViewData["FreightTypes"] = FreightTypes;
            }
            return(View(FreightModel1));
        }
Beispiel #6
0
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int rowIndex = e.RowIndex;

            Freight freight = new Freight();

            freight.Freight_id = Convert.ToInt32(this.GridView1.DataKeys[rowIndex].Value);

            FreightProvider provider = new FreightProvider();

            if (provider.Delete(freight))
            {
                this.Alert("删除成功!!!");

                if (this.txt_Name.Text == "")
                {
                    this.ListPager1.RecordCount = this.ListPager1.RecordCount - 1;
                    this.BindSource(null);
                }
                else
                {
                    this.ListPager1.RecordCount = this.ListPager1.RecordCount - 1;
                    this.BindSource("%" + this.txt_Name.Text + "%");
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 添加一条新的运费付汇方式
        /// </summary>
        /// <param unit="freight">新的运费付汇方式</param>
        /// <returns>添加成功返回true,否则返回false</returns>
        public bool Insert(Freight freight)
        {
            if (String.IsNullOrEmpty(freight.Freight_name))
            {
                return(false);
            }

            try
            {
                string commandText = "INSERT INTO t_freight VALUES (@freight_name)";

                DataParameter parmName = new DataParameter();
                parmName.ParameterName = "@freight_name";
                parmName.DbType        = DbType.String;
                parmName.Value         = freight.Freight_name;

                IList parameters = new ArrayList();
                parameters.Add(parmName);

                return(this.handler.ExecuteCommand(commandText, parameters));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #8
0
        /// <summary>
        /// 修改运费付汇方式的内容
        /// </summary>
        /// <param name="freight">新的运费付汇方式</param>
        /// <returns>修改成功返回true,否则返回false</returns>
        public bool Update(Freight freight)
        {
            if (freight.Freight_id == 0)
            {
                return(false);
            }

            string commandText = " UPDATE  t_freight " +
                                 " SET freight_name=@freight_name " +
                                 " WHERE freight_id=@freight_id ";

            DataParameter parmID = new DataParameter();

            parmID.ParameterName = "@freight_id";
            parmID.DbType        = DbType.Int32;
            parmID.Value         = freight.Freight_id;

            DataParameter parmName = new DataParameter();

            parmName.ParameterName = "@freight_name";
            parmName.DbType        = DbType.String;
            parmName.Value         = freight.Freight_name;

            IList parameters = new ArrayList();

            parameters.Add(parmID);
            parameters.Add(parmName);

            return(this.handler.ExecuteCommand(commandText, parameters));
        }
Beispiel #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SetName = "Freight";

            if (!IsPostBack)
            {
                if (Request.Params["FreightID"] != null)
                {
                    CurrentWeighingId = new Guid(Request.Params["FreightID"].ToString());
                    CurrentPageNr     = 22;

                    // locate the freight number and display it in the proper box
                    Freight frg = Freight.SelectFreightByFreightId(CurrentWeighingId, new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session));
                    if (frg != null)
                    {
                        TextBoxOrderNumber.Text = frg.OurReference.ToString();
                        //LoadFirstWeighingData(frg);
                    }

                    CurrentPageNr = 21;
                    EnableCorrectScreenElements();
                    CurrentPageNr = 22;
                    EnableCorrectScreenElements();

                    if (frg.FreightStatus != "2nd weighing")
                    {
                        Response.Redirect(Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.IndexOf("?")));
                    }
                }
            }
        }
Beispiel #10
0
        public async Task <Result <Freight> > Create(CreateFreightViewModel viewModel)
        {
            var maybeState = await _stateRepository.FindById(viewModel.StateId);

            if (maybeState.HasNoValue)
            {
                return(Result.Fail <Freight>("Estado não existe"));
            }

            var state = maybeState.Value;

            var value = new FreightValue
            {
                Name         = $"{viewModel.Name} {state.Name}",
                Price        = viewModel.Price,
                BeginZipCode = state.BeginZipCode,
                EndZipCode   = state.EndZipCode,
                BeginWeight  = 0,
                EndWeight    = 0,
                Deadline     = viewModel.Deadline
            };

            var values = new List <FreightValue>
            {
                value
            };

            var freight = new Freight
            {
                Name   = viewModel.Name,
                Values = values
            };

            return(Result.Ok(freight));
        }
Beispiel #11
0
        public void SaveSecondWeighingData(Freight frg, ModelTMSContainer ControlObjectContext)
        {
            FreightWeighing         fgw = frg.FreightWeighing.First <FreightWeighing>();
            FreightWeighingMaterial fwm = fgw.FreightWeighingMaterial.First <FreightWeighingMaterial>();

            fgw.WeighingDateTime2 = CalendarWithTimeControl2.SelectedDateTime;
            fgw.Key2 = TextBoxKey2.Text;
            try { fgw.Weight2 = Convert.ToDouble("0" + TextBoxWeight2.Text); }  catch { };
            fwm.TarraWeight    = fgw.Weight2;
            fwm.NetWeight      = fwm.GrossWeight - fwm.TarraWeight;
            frg.TotalNetWeight = fwm.NetWeight;
            frg.Description    = TextBoxDescription.Text;
            frg.Comments       = TextBoxComments.Text;
            frg.FreightStatus  = "Done";

            frg.RecalcTotalWeightFromWeighing();

            if (CheckBoxWeighingActionSort.Checked)
            {
                frg.FreightStatus = "In sorting";
            }
            if (CheckBoxWeighingActionInvoice.Checked)
            {
                frg.FreightStatus = "To be invoiced";
            }
        }
Beispiel #12
0
        public IActionResult Index()
        {
            var typeFreightSelectedByUser = _cookie.Consult("cart.typefreight");

            if (typeFreightSelectedByUser != null)
            {
                var addressAdressId = int.Parse(_cookie.Consult("ShoppingCart.Address").Replace("-end", ""));
                int cep             = 0;
                if (addressAdressId == 0)
                {
                    cep = int.Parse(Mask.Remove(_clientLogin.GetClient().Zipcode));
                }
                else
                {
                    var address = _deliveryAddressRepository.GetAddress(addressAdressId);
                    cep = int.Parse(Mask.Remove(address.Zipcode));
                }

                var hashCart = GenerateHashAndSerialize(_cookieShoppingCart.Consult());

                Freight freight = _cookieFreight.Consult().Where(c => c.CEP == cep && c.ShoppingCartCode == hashCart).FirstOrDefault();

                if (freight != null)
                {
                    ViewBag.Freight = freight.ListValues.Where(f => f.TypeFreight == typeFreightSelectedByUser).First();
                    List <ProductItem> products = LoadProductDb();
                    return(View(products));
                }
            }
            TempData["MSG_E"] = Message.MSG_E009;
            return(RedirectToAction("Index", "ShoppingCart"));
        }
        protected void btn_sure_Click(object sender, EventArgs e)
        {
            Freight         freight  = this.AddFreight();
            FreightProvider provider = new FreightProvider();

            switch (this.OperationFlag)
            {
            case Operation.Add:
                if (this.IsSame() == 1)
                {
                    break;
                }
                if (provider.Insert(freight))
                {
                    this.Alert("添加成功!!!");
                    this.TextCancel();
                }
                break;

            case Operation.Update:
                if (provider.Update(freight))
                {
                    this.Alert("修改成功!!!");
                    this.BindText();
                }
                break;
            }
        }
Beispiel #14
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 17;
         hash = hash * 23 + (AccountNumber == null ? 0 : AccountNumber.GetHashCode());
         hash = hash * 23 + (BillToAddressId == default(int) ? 0 : BillToAddressId.GetHashCode());
         hash = hash * 23 + (Comment == null ? 0 : Comment.GetHashCode());
         hash = hash * 23 + (CreditCardApprovalCode == null ? 0 : CreditCardApprovalCode.GetHashCode());
         hash = hash * 23 + (CreditCardId == null ? 0 : CreditCardId.GetHashCode());
         hash = hash * 23 + (CurrencyRateId == null ? 0 : CurrencyRateId.GetHashCode());
         hash = hash * 23 + (CustomerId == default(int) ? 0 : CustomerId.GetHashCode());
         hash = hash * 23 + (DueDate == default(DateTime) ? 0 : DueDate.GetHashCode());
         hash = hash * 23 + (Freight == default(decimal) ? 0 : Freight.GetHashCode());
         hash = hash * 23 + (ModifiedDate == default(DateTime) ? 0 : ModifiedDate.GetHashCode());
         hash = hash * 23 + (OnlineOrderFlag == default(bool) ? 0 : OnlineOrderFlag.GetHashCode());
         hash = hash * 23 + (OrderDate == default(DateTime) ? 0 : OrderDate.GetHashCode());
         hash = hash * 23 + (PurchaseOrderNumber == null ? 0 : PurchaseOrderNumber.GetHashCode());
         hash = hash * 23 + (RevisionNumber == default(byte) ? 0 : RevisionNumber.GetHashCode());
         hash = hash * 23 + (Rowguid == default(Guid) ? 0 : Rowguid.GetHashCode());
         hash = hash * 23 + (SalesOrderNumber == null ? 0 : SalesOrderNumber.GetHashCode());
         hash = hash * 23 + (SalesPersonId == null ? 0 : SalesPersonId.GetHashCode());
         hash = hash * 23 + (ShipDate == null ? 0 : ShipDate.GetHashCode());
         hash = hash * 23 + (ShipMethodId == default(int) ? 0 : ShipMethodId.GetHashCode());
         hash = hash * 23 + (ShipToAddressId == default(int) ? 0 : ShipToAddressId.GetHashCode());
         hash = hash * 23 + (Status == default(byte) ? 0 : Status.GetHashCode());
         hash = hash * 23 + (SubTotal == default(decimal) ? 0 : SubTotal.GetHashCode());
         hash = hash * 23 + (TaxAmt == default(decimal) ? 0 : TaxAmt.GetHashCode());
         hash = hash * 23 + (TerritoryId == null ? 0 : TerritoryId.GetHashCode());
         hash = hash * 23 + (TotalDue == default(decimal) ? 0 : TotalDue.GetHashCode());
         return(hash);
     }
 }
Beispiel #15
0
        public List <Freight> GetFreightByBookingId(int bookingId)
        {
            SqlCommand cmd = new SqlCommand("GetFreightByBookingId");

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@bookingId", SqlDbType.Int).Value = bookingId;
            DataTable result = base.FillDataTable(cmd);

            List <Freight> listFr = new List <Freight>();

            foreach (DataRow r in result.Rows)
            {
                Freight f = new Freight
                {
                    Id        = int.Parse(r["Id"].ToString()),
                    BookingId = int.Parse(r["BookingId"].ToString()),
                    Code      = r["Code"].ToString(),
                    BS        = r["BS"].ToString(),
                    PC        = r["PC"].ToString(),
                    Units     = int.Parse(r["Units"].ToString()),
                    Rate      = decimal.Parse(r["Rate"].ToString(), NumberStyles.Currency),
                    AmtPPD    = decimal.Parse(r["AmtPPD"].ToString(), NumberStyles.Currency),
                    AmtCOL    = decimal.Parse(r["AmtCOL"].ToString(), NumberStyles.Currency),
                    BrkRate   = decimal.Parse(r["BrkRate"].ToString(), NumberStyles.Currency),
                    BrkAmt    = decimal.Parse(r["BrkAmt"].ToString(), NumberStyles.Currency)
                };
                listFr.Add(f);
            }

            return(listFr);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ComboBoxWeighingLocation.DataBind();
                ComboBoxCustomer.DataBind();

                // parse the FreightId and link this one up to that freight
                if (Request.Params["FreightId"] != null)
                {
                    //ModelTMSContainer ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session);

                    CurrentWeighingId = new Guid(Request.Params["FreightId"].ToString());

                    Freight frg = Freight.SelectFreightByFreightId(CurrentWeighingId, ControlObjectContext);

                    if ((frg.FreightStatus == "In sorting") && (frg.FreightSortingMaterial.Count == 0))
                    {
                        // only create a new sorting form for an existing weighing if this weighing is "In sorting" and not filled in yet
                        PrepareOldWeighingForSorting();

                        // show form
                        CurrentPageNr = 2;
                    }
                    else
                    {
                        CurrentWeighingId = Guid.Empty;
                    }
                }

                Common.LimitLocationList(ComboBoxWeighingLocation.Items, Session, ControlObjectContext);
                ShowCorrectCustomer();
            }
        }
Beispiel #17
0
        /// <summary>
        /// 利用分页机制,根据指定的过滤条件查询运费付汇方式
        /// </summary>
        /// <param name="freight">过滤条件</param>
        /// <param name="start">起始行</param>
        /// <param name="max">获取记录行的总数</param>
        /// <returns></returns>
        public DataTable Select(Freight freight, int start, int max)
        {
            StringBuilder commandText = new StringBuilder();

            commandText.Append("SELECT * FROM t_freight WHERE 1=1 ");
            IList parameters = new ArrayList();

            if (freight.Freight_id != 0)
            {
                commandText.Append(" AND freight_id=@freight_id ");
                DataParameter parmID = new DataParameter();
                parmID.ParameterName = "@freight_id";
                parmID.DbType        = DbType.Int32;
                parmID.Value         = freight.Freight_id;
                parameters.Add(parmID);
            }

            if (!String.IsNullOrEmpty(freight.Freight_name))
            {
                commandText.Append(" AND freight_name like @freight_name ");

                DataParameter parmName = new DataParameter();
                parmName.ParameterName = "@freight_name";
                parmName.DbType        = DbType.String;
                parmName.Value         = freight.Freight_name;
                parameters.Add(parmName);
            }



            return(this.handler.Query(commandText.ToString(), parameters, start, max));
        }
Beispiel #18
0
        public Task <Result <Freight> > Create(CreateFreightViewModel viewModel)
        {
            var value = new FreightValue
            {
                Name         = viewModel.Name,
                Price        = viewModel.Price,
                BeginZipCode = "0",
                EndZipCode   = "0",
                BeginWeight  = 0,
                EndWeight    = 0,
                Deadline     = viewModel.Deadline
            };

            var values = new List <FreightValue>()
            {
                value
            };

            var freight = new Freight
            {
                Name   = viewModel.Name,
                Values = values
            };

            var result = Result.Ok(freight);

            return(Task.FromResult(result));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // check if a freight is given on the Url
                if (Request.Params["FreightId"] != null)
                {
                    Freight frg = Freight.SelectFreightByFreightId(new Guid(Request.Params["FreightId"]), new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session));
                    if (frg != null)
                    {
                        TextBoxOrderNumber.Text = frg.OurReference.ToString();
                        CurrentPageNr           = 2;
                        EnableCorrectScreenElements();

                        if (Request.Params["Speed"] != null)
                        {
                            CurrentPageNr = 3;
                            EnableCorrectScreenElements();
                            if (WebUserControlCashPurchase1.Visible)
                            {
                                WebUserControlCashPurchase1.FreightSpeedCycle();
                            }
                            else
                            {
                                WebUserControlNonCashPurchase1.FreightSpeedCycle();
                            }
                        }
                    }
                }
            }
        }
Beispiel #20
0
        // POST api/values
        public int Post([FromBody] string freight)
        {
            JsonSerializerSettings serializerSettings = new JsonSerializerSettings {
                Formatting = Formatting.Indented
            };
            Freight u = JsonConvert.DeserializeObject <Freight>(freight, serializerSettings);

            return(FreightBLL.InsertFreight(u));
        }
Beispiel #21
0
        protected bool ProcessFirstWeighing()
        {
            ModelTMSContainer ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session);
            bool Success = false;

            // start transaction
            using (TransactionScope TS = new TransactionScope())
            {
                try
                {
                    // process freight
                    // setup base objects
                    Freight                 frg  = new Freight();
                    FreightWeighing         frgw = new FreightWeighing();
                    FreightWeighingMaterial frgm = new FreightWeighingMaterial();
                    frg.FreightWeighing.Add(frgw);
                    frgw.FreightWeighingMaterial.Add(frgm);

                    ControlObjectContext.AddToFreightSet(frg);

                    // save the first weighing data in the freight
                    SaveFirstWeighingData(frg, ControlObjectContext);

                    // assign the weighing number
                    frg.AssignFreightNumber(ControlObjectContext);
                    LabelFreightNr.Text = frg.OurReference.ToString();
                    CurrentWeighingId   = frg.Id;
                    frg.Description     = "Weegbon " + frg.OurReference + " / " + Common.CurrentClientDateTime(Session).ToString();
                    frg.FreightType     = "Weighing";

                    // and save to persistent storage
                    ControlObjectContext.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave);

                    // commit the transaciton
                    TS.Complete();
                    Success = true;
                }
                catch (Exception ex) // commit or procedure failed somewhere
                {
                    // rollback transaction
                    TS.Dispose();

                    // inform user
                    Common.InformUserOnTransactionFail(ex, Page);

                    // reset the weighing id when not saved
                    CurrentWeighingId = Guid.Empty;
                }
            }

            if (Success)
            {
                // when success advance panel
                CurrentPageNr++;
            }
            return(Success);
        }
Beispiel #22
0
        public ActionResult Add(FreightAddViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                using (UnitOfWork uow = new UnitOfWork())
                {
                    var userId    = User.Identity.GetUserId();
                    var companyId = int.Parse(User.Identity.GetCompanyId());
                    var company   = uow.FindObject <Company>(CriteriaOperator.Parse("Oid==?", companyId));
                    var freight   = new Freight(uow)
                    {
                        EndDate = model.EndDate,
                        EndLocationCoordinates = model.EndLocationCoordinates,
                        EndLocationCountry     = model.EndLocationCountry,
                        EndLocationName        = model.EndLocationName,
                        EndLocationZip         = model.EndLocationZip,
                        OfferredPrice          = model.OfferredPrice,
                        StartDate = model.StartDate,
                        StartLocationCoordinates = model.StartLocationCoordinates,
                        StartLocationCountry     = model.StartLocationCountry,
                        StartLocationName        = model.StartLocationName,
                        StartLocationZip         = model.StartLocationZip,
                        StartLat           = model.StartLat,
                        StartLon           = model.StartLon,
                        EndLat             = model.EndLat,
                        EndLon             = model.EndLon,
                        Notes              = model.Notes,
                        ConactPersonName   = model.ContactPersonName,
                        ContactPersonPhone = model.ContactPersonPhone,
                        ContactPersonEmail = model.ContactPersonEmail,
                        UserId             = userId,
                        TruckId            = model.TruckId,
                        CreatedOn          = DateTime.Now,
                    };
                    company.Freights.Add(freight);
                    uow.CommitChanges();



                    try
                    {
                        //await SendEmail(load.LoadId);
                        return(RedirectToAction("Freights", "Client"));
                    }
                    catch (Exception e)
                    {
                        ViewBag.errorMessage = e.Message;
                        return(View("Error"));
                    }
                }
            }
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            Bus      bus     = new Bus("Bogdan");
            Freight  freight = new Freight("VW Transporter");
            SuperCar super   = new SuperCar("Ferrari");

            super.Go();
            bus.Go();
            freight.Go();
        }
        public async Task <Result <Freight> > Create(CreateFreightViewModel viewModel)
        {
            var maybeState = await _stateRepository.FindById(viewModel.StateId);

            if (maybeState.HasNoValue)
            {
                return(Result.Fail <Freight>("Estado não existe"));
            }

            var state = maybeState.Value;

            var tasks = viewModel.CitiesId.Select(async it =>
            {
                var maybeCity = await _cityRepository.FindById(viewModel.StateId, it);

                if (maybeCity.HasNoValue)
                {
                    return(Result.Fail <FreightValue>("Cidade não existe"));
                }

                var city = maybeCity.Value;

                var value = new FreightValue
                {
                    Name         = $"{viewModel.Name} {state.Name} {city.Name}",
                    Price        = viewModel.Price,
                    BeginZipCode = city.BeginZipCode,
                    EndZipCode   = city.EndZipCode,
                    BeginWeight  = 0,
                    EndWeight    = 0,
                    Deadline     = viewModel.Deadline
                };

                return(Result.Ok(value));
            });

            var results = await Task.WhenAll(tasks);

            var result = Result.Combine(results);

            if (result.Failure)
            {
                return(Result.Fail <Freight>(result.Message));
            }

            var values = results.Select(it => it.Value);

            var freigth = new Freight
            {
                Name   = viewModel.Name,
                Values = values
            };

            return(Result.Ok(freigth));
        }
        public async Task <IActionResult> CalculateFreight(int cepDestiny)
        {
            try
            {
                //Verify if exists at freight the calculate for same CEP and products
                Freight freight = _cookieFreight.Consult().Where(a => a.CEP == cepDestiny && a.ShoppingCartCode == GenerateHashAndSerialize(_cookieShoppingCart.Consult())).FirstOrDefault();
                if (freight != null)
                {
                    return(Ok(freight));
                }
                else
                {
                    List <ProductItem> products = LoadProductDb();

                    List <Package> packages = _calculatePackage.CalculatingPackage(products);

                    ValueDeadlineFreight valuesPAC = await _wSCorreiosCalculateFreight.CalculateFreight(cepDestiny.ToString(), TypeFreightConstant.PAC, packages);

                    ValueDeadlineFreight valuesSEDEX = await _wSCorreiosCalculateFreight.CalculateFreight(cepDestiny.ToString(), TypeFreightConstant.SEDEX, packages);

                    ValueDeadlineFreight valuesSEDEX10 = await _wSCorreiosCalculateFreight.CalculateFreight(cepDestiny.ToString(), TypeFreightConstant.SEDEX10, packages);

                    List <ValueDeadlineFreight> list = new List <ValueDeadlineFreight>();
                    if (valuesPAC != null)
                    {
                        list.Add(valuesPAC);
                    }
                    if (valuesSEDEX != null)
                    {
                        list.Add(valuesSEDEX);
                    }
                    if (valuesSEDEX10 != null)
                    {
                        list.Add(valuesSEDEX10);
                    }


                    freight = new Freight()
                    {
                        CEP = cepDestiny,
                        ShoppingCartCode = GenerateHashAndSerialize(_cookieShoppingCart.Consult()),
                        ListValues       = list
                    };

                    _cookieFreight.Register(freight);

                    return(Ok(freight));
                }
            }

            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
Beispiel #26
0
        public static Freight FreightGenerator()
        {
            double weight = rnd.Next(-3, 10) * rnd.NextDouble();
            double a      = rnd.Next(-3, 10) * rnd.NextDouble();
            double b      = rnd.Next(-3, 10) * rnd.NextDouble();
            double c      = rnd.Next(-3, 10) * rnd.NextDouble();
            var    res    = new Freight(weight, a, b, c);

            Console.WriteLine(res);
            return(res);
        }
        private Freight AddFreight()
        {
            Freight freight = new Freight();

            if (Request.QueryString["id"] != null)
            {
                freight.Freight_id = Convert.ToInt32(id);
            }
            freight.Freight_name = this.txt_name.Text;
            return(freight);
        }
Beispiel #28
0
 private void UpdateDenominations(ForeignCurrency value)
 {
     Freight.UpdateDenomination(value);
     if (Items != null)
     {
         foreach (var itm in Items)
         {
             itm.UnitCost.UpdateDenomination(value);
         }
     }
 }
Beispiel #29
0
        protected void btn_Result_Click(object sender, EventArgs e)
        {
            Freight freight = new Freight();

            freight.Freight_name = "%" + this.txt_Name.Text + "%";
            FreightProvider provider = new FreightProvider();

            this.ListPager1.RecordCount = provider.GetSize(freight);
            this.BindSource(0, "%" + this.txt_Name.Text + "%");
            this.ListPager1.PageChange += new PagerEventHandler(ListPager1_PageChange);
        }
        public void Remove(Freight item)
        {
            var list          = Consult();
            var itemLocalized = list.SingleOrDefault(i => i.CEP == item.CEP);

            if (itemLocalized != null)
            {
                list.Remove(itemLocalized);
                Save(list);
            }
        }