Exemplo n.º 1
0
        public JsonResult SaveRoute(int Id, string Code, string Name, int OrginLocationID, int DestinationId, string Details)
        {
            try
            {
                var acopeningmaster = (from d in db.RouteMasters where d.RouteID == Id select d).FirstOrDefault();
                if (acopeningmaster == null)
                {
                    acopeningmaster = new RouteMaster();
                }
                else
                {
                    var details = (from d in db.RouteOrders where d.RouteID == acopeningmaster.RouteID select d).ToList();
                    db.RouteOrders.RemoveRange(details);
                    db.SaveChanges();
                }
                acopeningmaster.RouteCode             = Code;
                acopeningmaster.RouteName             = Name;
                acopeningmaster.OrginLocationID       = OrginLocationID;
                acopeningmaster.DestinationLocationID = DestinationId;

                if (acopeningmaster.RouteID == 0)
                {
                    db.RouteMasters.Add(acopeningmaster);
                }
                db.SaveChanges();
                var IDetails = JsonConvert.DeserializeObject <List <DepotVM> >(Details);
                foreach (var item in IDetails)
                {
                    var InvoiceDetail = new RouteOrder();
                    InvoiceDetail.RouteID   = acopeningmaster.RouteID;
                    InvoiceDetail.DepotID   = item.ID;
                    InvoiceDetail.StopOrder = item.AgentID;

                    db.RouteOrders.Add(InvoiceDetail);
                    db.SaveChanges();
                }
                return(Json(new { status = "ok", message = "Route Submitted Successfully!" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new { status = "failed", message = e.Message.ToString() }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 2
0
        private float CalculateDriverOrderMultiplier(RouteDriver Driver, RouteOrder Order, IEnumerable <OptimizationTag> Multipliers)
        {
            float result = 1.0f;

            string[] orderTags = Order.Tags.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string tag in orderTags)
            {
                OptimizationTag optimizationTag = (from m in Multipliers where
                                                   (m.Name == tag) ||
                                                   (m.Name.Contains("*") && tag.StartsWith(m.Name.Substring(0, m.Name.IndexOf("*")))) &&                 // handle wildcards
                                                   m.IsExclusive
                                                   select m)
                                                  .FirstOrDefault();

                if (optimizationTag != null && !Driver.Tags.Contains(tag))
                {
                    // If optimization tag is not found for the driver, apply multiplier
                    result += (optimizationTag.Multiplier - 1.0f);                     // multiplier is additive, not compounding
                }
            }

            return(result);
        }