Ejemplo n.º 1
0
        public ActionResult DirectLineEdit(int id, [Bind(Include = "start,length,search")] RouteValue routeValue)
        {
            if (!MyHelp.CheckAuth("shipping", "directLine", EnumData.AuthType.Edit))
            {
                RedirectToAction("index", "main");
            }

            using (IRepository <DirectLine> DirectLine = new GenericRepository <DirectLine>())
            {
                DirectLine directLine = DirectLine.Get(id);

                if (directLine == null)
                {
                    return(HttpNotFound());
                }

                if (TryUpdateModel(directLine) && ModelState.IsValid)
                {
                    directLine.CountryName = MyHelp.GetCountries().First(c => c.TwoCode.Equals(directLine.CountryCode)).Name;
                    DirectLine.SaveChanges();

                    MyHelp.Log("DirectLine", directLine.ID, "編輯DL運輸廠商");
                    return(RedirectToAction("directLine", "shipping", routeValue));
                }

                ViewBag.routeValue = routeValue;
                return(View(directLine));
            }
        }
Ejemplo n.º 2
0
 public void Save(RouteValue routeValue)
 {
     if (!Exists(routeValue))
     {
         routeValues.Add(routeValue);
     }
 }
Ejemplo n.º 3
0
        public ActionResult Edit(int?id, [Bind(Include = "start,length,search,gId")] RouteValue routeValue)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            AdminUsers user = AdminUsers.Get(id.Value);

            if (user == null)
            {
                return(HttpNotFound());
            }

            Warehouses            = new GenericRepository <Warehouses>(db);
            ViewBag.warehouseList = Warehouses.GetAll(true).Where(w => w.IsEnable == true && w.IsSellable == true).ToList();
            ViewBag.timeZoneList  = new Dictionary <EnumData.TimeZone, string>()
            {
                { EnumData.TimeZone.EST, "Eastern Standard Time" }, { EnumData.TimeZone.TST, "Taipei Standard Time" }, { EnumData.TimeZone.PST, "Pacific Standard Time" },
                { EnumData.TimeZone.GMT, "Greenwich Mean Time" }, { EnumData.TimeZone.AEST, "AUS Eastern Standard Time" }, { EnumData.TimeZone.JST, "Tokyo Standard Time" }
            };

            IEnumerable <AdminGroups> groupList = AdminGroups.GetAll(true).Where(g => g.IsEnable && g.IsVisible).OrderBy(g => g.Order);

            ViewData["groupList"] = new SelectList(groupList, "Id", "name", user.GroupId);

            ViewBag.routeValue = routeValue;
            return(View("~/Views/admin/users/edit.cshtml", user));
        }
Ejemplo n.º 4
0
        public ActionResult Delete(int id, [Bind(Include = "start,length,search")] RouteValue routeValue)
        {
            if (!MyHelp.CheckAuth("group", "index", EnumData.AuthType.Insert))
            {
                return(RedirectToAction("index", "main"));
            }

            AdminGroups group = AdminGroups.Get(id);

            if (group == null)
            {
                return(HttpNotFound());
            }

            group.IsEnable = false;
            AdminGroups.Update(group);
            AdminGroups.SaveChanges();

            MyHelp.Log("AdminGroups", group.Id, "刪除管理員群組");

            IEnumerable <AdminGroups> results = AdminGroups.GetAll().Where(g => g.IsEnable).OrderBy(g => g.Order).ToList();

            if (results.Any())
            {
                int order = 1;
                foreach (AdminGroups data in results)
                {
                    data.Order = order++;
                    AdminGroups.Update(data);
                }
            }
            AdminGroups.SaveChanges();

            return(RedirectToAction("index", "group", routeValue));
        }
Ejemplo n.º 5
0
        public ActionResult Index([Bind(Include = "start,length,search,gId")] RouteValue routeValue)
        {
            ViewBag.groupList = AdminGroups.GetAll(true).Where(g => g.IsEnable && g.IsVisible).OrderBy(g => g.Order).ToList();

            ViewBag.routeValue = routeValue;
            return(View("~/Views/admin/users/index.cshtml"));
        }
Ejemplo n.º 6
0
        private IList <RouteValue> ReadParameters(MethodCallExpression methodCall)
        {
            var values = new List <RouteValue>();

            var attributeRecogniser = new AttributeRecogniser();
            var propertyReader      = new PropertyReader();

            var parameters = methodCall.Method.GetParameters();
            var arguments  = methodCall.Arguments;

            for (int i = 0; i < parameters.Length; i++)
            {
                var param            = parameters[i];
                var expectedValue    = GetExpectedValue(arguments[i]);
                var isFromBody       = attributeRecogniser.IsFromBody(param);
                var routeValueOrigin = isFromBody ? RouteValueOrigin.Body : RouteValueOrigin.Unknown;
                if (expectedValue != null || !isFromBody)
                {
                    if (propertyReader.IsSimpleType(param.ParameterType))
                    {
                        var resultValue = new RouteValue(param.Name, expectedValue, routeValueOrigin);
                        values.Add(resultValue);
                    }
                    else
                    {
                        var objectFieldValues = propertyReader.PropertiesList(expectedValue, routeValueOrigin)
                                                .Where(x => x.Value != null);
                        values.AddRange(objectFieldValues);
                    }
                }
            }

            return(values);
        }
Ejemplo n.º 7
0
        public ActionResult DirectLineEdit(int?id, [Bind(Include = "start,length,search")] RouteValue routeValue)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (!MyHelp.CheckAuth("shipping", "directLine", EnumData.AuthType.Edit))
            {
                RedirectToAction("index", "main");
            }

            using (IRepository <DirectLine> DirectLine = new GenericRepository <DirectLine>())
            {
                DirectLine directLine = DirectLine.Get(id.Value);

                if (directLine == null)
                {
                    return(HttpNotFound());
                }

                ViewBag.routeValue = routeValue;
                return(View(directLine));
            }
        }
Ejemplo n.º 8
0
        public void WhenSaveRouteValueThenSaveInRepository()
        {
            var routeValue = new RouteValue("FRO", "TO", 10);

            routeService.Save(routeValue);

            repository.Received().Save(routeValue);
        }
Ejemplo n.º 9
0
        private static RouteValues RouteValuesContainingId()
        {
            var values  = new RouteValues();
            var idValue = new RouteValue("Id", 42, RouteValueOrigin.Unknown);

            values.Add(idValue);

            return(values);
        }
Ejemplo n.º 10
0
        public void SetUp()
        {
            var routeValue = new RouteValue(FROM, TO, VALUE);

            routes = new List <RouteValue> {
                routeValue
            };

            graphCreator = new GraphCreator();
        }
Ejemplo n.º 11
0
 public ActionResult <string> Post([FromBody] RouteValue routeValue)
 {
     try
     {
         routeService.Save(routeValue);
         return(Created("api/route", routeValue));
     }
     catch (BusinessException e)
     {
         return(ValidationProblem(e.Message, null, StatusCodes.Status400BadRequest));
     }
 }
Ejemplo n.º 12
0
        public static void Start()
        {
            var routes = RouteTable.Routes;

            routes.Map("({lang}/)({controller}/){action}/", new MvcRouteHandler(),
                       incomingDefaults: new
            {
                lang       = RouteValue.Dynamic(() => Thread.CurrentThread.CurrentUICulture.Name.ToLowerInvariant()),
                controller = "Elastic"
            },
                       outgoingDefaults: new
            {
                lang = RouteValue.FromRequest()
            },
                       constraints: new
            {
                lang   = @"\w{2}-\w{2}",
                action = @"\w+"
            }
                       );

            routes.Map("({lang}/){*path}/{id}/({title}(.{format}))",
                       new DecoratedRouteHandler(new MvcRouteHandler(), new NavigationRouteDecorator()),
                       constraints: new
            {
                lang   = @"\w{2}-\w{2}",
                id     = @"\d+",
                title  = @"[^\./]+",
                format = new Constraints.DelegatedConstraint(v => v == null || v == "json" || v == "xml" || v == "html")
            },
                       incomingDefaults: new
            {
                format = "html"
            }
                       );

            routes.Map("({lang}/)", new MvcRouteHandler(),
                       constraints: new
            {
                lang = @"\w{2}-\w{2}"
            },
                       incomingDefaults: new
            {
                controller = "Elastic",
                action     = "page"
            },
                       routeName: "Homepage"
                       );
        }
Ejemplo n.º 13
0
        public ActionResult Delete(int id, [Bind(Include = "start,length,search,gId")] RouteValue routeValue)
        {
            if (!MyHelp.CheckAuth("user", "index", EnumData.AuthType.Delete))
            {
                return(RedirectToAction("index", "main"));
            }

            AdminUsers user = AdminUsers.Get(id);

            user.IsEnable = false;
            AdminUsers.Update(user);
            AdminUsers.SaveChanges();

            MyHelp.Log("AdminUsers", user.Id, "刪除管理員");
            return(RedirectToAction("index", "user", routeValue));
        }
Ejemplo n.º 14
0
        public ActionResult Apidelete(int id, [Bind(Include = "start,length,search")] RouteValue routeValue)
        {
            CarrierAPI api = CarrierAPI.Get(id);

            if (api == null)
            {
                return(HttpNotFound());
            }

            api.IsEnable = false;
            CarrierAPI.Update(api);
            CarrierAPI.SaveChanges();

            MyHelp.Log("CarrierAPI", api.Id, "刪除連線API");
            return(RedirectToAction("api", "shipping", routeValue));
        }
Ejemplo n.º 15
0
        public ActionResult Apiedit(int?id, [Bind(Include = "start,length,search")] RouteValue routeValue)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            CarrierAPI api = CarrierAPI.Get(id.Value);

            if (api == null)
            {
                return(HttpNotFound());
            }

            ViewBag.routeValue = routeValue;
            return(View(api));
        }
Ejemplo n.º 16
0
        public ActionResult Edit(int?id, [Bind(Include = "start,length,search")] RouteValue routeValue)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            AdminGroups group = AdminGroups.Get(id.Value);

            if (group == null)
            {
                return(HttpNotFound());
            }

            ViewBag.routeValue = routeValue;
            ViewBag.menuList   = Menu.GetAll().Where(m => m.IsEnable == true && m.PrevId == 0).OrderBy(m => m.Order).ToList();
            return(View("~/Views/admin/groups/edit.cshtml", group));
        }
Ejemplo n.º 17
0
        public IList <RouteValue> ReadBody(string body)
        {
            var values = new List <RouteValue>();

            if (string.IsNullOrWhiteSpace(body))
            {
                return(values);
            }

            var json = JObject.Parse(body);

            foreach (var jsonProp in json.Properties())
            {
                var routeValue = new RouteValue(jsonProp.Name, ConvertValue(jsonProp.Value), RouteValueOrigin.Body);
                values.Add(routeValue);
            }

            return(values);
        }
Ejemplo n.º 18
0
        public ActionResult Apiedit(int id, [Bind(Include = "start,length,search")] RouteValue routeValue)
        {
            CarrierAPI api = CarrierAPI.Get(id);

            if (api == null)
            {
                return(HttpNotFound());
            }

            if (TryUpdateModel(api) && ModelState.IsValid)
            {
                CarrierAPI.SaveChanges();

                MyHelp.Log("CarrierAPI", api.Id, "編輯連線API");
                return(RedirectToAction("api", "shipping", routeValue));
            }

            ViewBag.routeValue = routeValue;
            return(View(api));
        }
Ejemplo n.º 19
0
        public ActionResult Edit(int id, AdminUsers data, List <int> warehouse, [Bind(Include = "start,length,search,gId,id")] RouteValue routeValue)
        {
            if (!MyHelp.CheckAuth("user", "index", EnumData.AuthType.Edit))
            {
                return(RedirectToAction("index", "main"));
            }

            AdminUsers user = AdminUsers.Get(id);

            if (user != null)
            {
                user.IsEnable    = data.IsEnable;
                user.IsVisible   = data.IsVisible;
                user.GroupId     = data.GroupId;
                user.Name        = data.Name;
                user.Account     = data.Account;
                user.Password    = string.IsNullOrEmpty(data.Password) ? user.Password : MyHelp.Encrypt(data.Password);
                user.ApiUserName = data.ApiUserName;
                user.ApiPassword = data.ApiPassword;
                user.Warehouse   = warehouse != null?JsonConvert.SerializeObject(warehouse) : null;

                user.TimeZone = data.TimeZone;

                AdminUsers.Update(user);
                AdminUsers.SaveChanges();

                MyHelp.Log("AdminUsers", user.Id, "編輯管理員");
                return(RedirectToAction("edit", "user", routeValue));
            }

            ViewBag.warehouseList = Warehouses.GetAll().Where(w => w.IsEnable == true && w.IsSellable == true).ToList();
            ViewBag.timeZoneList  = new Dictionary <EnumData.TimeZone, string>()
            {
                { EnumData.TimeZone.EST, "Eastern Standard Time" }, { EnumData.TimeZone.TST, "Taipei Standard Time" }, { EnumData.TimeZone.PST, "Pacific Standard Time" },
                { EnumData.TimeZone.GMT, "Greenwich Mean Time" }, { EnumData.TimeZone.AEST, "AUS Eastern Standard Time" }, { EnumData.TimeZone.JST, "Tokyo Standard Time" }
            };
            ViewBag.routeValue = routeValue;
            return(View("~/Views/admin/users/edit.cshtml", user));
        }
Ejemplo n.º 20
0
        public ActionResult DirectLineDelete(int id, [Bind(Include = "start,length,search")] RouteValue routeValue)
        {
            if (!MyHelp.CheckAuth("shipping", "directLine", EnumData.AuthType.Delete))
            {
                RedirectToAction("index", "main");
            }

            using (IRepository <DirectLine> DirectLine = new GenericRepository <DirectLine>())
            {
                DirectLine directLine = DirectLine.Get(id);

                if (directLine == null)
                {
                    return(HttpNotFound());
                }

                directLine.IsEnable = false;
                DirectLine.Update(directLine, directLine.ID);
                DirectLine.SaveChanges();

                MyHelp.Log("DirectLine", directLine.ID, "刪除DL運輸廠商");
                return(RedirectToAction("directLine", "shipping", routeValue));
            }
        }
Ejemplo n.º 21
0
 public bool Exists(RouteValue routeValue)
 {
     return(routeValues.Exists(route => route.From == routeValue.From && route.To == routeValue.To));
 }
Ejemplo n.º 22
0
 public ActionResult Index([Bind(Include = "start,length,search")] RouteValue routeValue)
 {
     ViewBag.routeValue = routeValue;
     return(View("~/Views/admin/groups/index.cshtml"));
 }
Ejemplo n.º 23
0
 public void Create(RouteValue routeValue)
 {
     travelRouteApi.PostSync <RouteValue>("api/route", routeValue);
 }
Ejemplo n.º 24
0
        public ActionResult Edit(int id, AdminGroups group, Dictionary <string, List <bool> > auth, [Bind(Include = "start,length,search")] RouteValue routeValue)
        {
            if (!MyHelp.CheckAuth("group", "index", EnumData.AuthType.Edit))
            {
                return(RedirectToAction("index", "main"));
            }

            group.Auth = JsonConvert.SerializeObject(auth.ToDictionary(a => Convert.ToInt32(a.Key), a => a.Value));
            if (group != null)
            {
                AdminGroups.Update(group);
                AdminGroups.SaveChanges();
                routeValue.id = id;

                MyHelp.Log("AdminGroups", group.Id, "編輯管理員群組");
                return(RedirectToAction("edit", "group", routeValue));
            }

            ViewBag.routeValue = routeValue;
            ViewBag.menuList   = Menu.GetAll().Where(m => m.IsEnable == true && m.PrevId == 0).OrderBy(m => m.Order).ToList();
            return(View("~/Views/admin/groups/edit.cshtml", group));
        }
Ejemplo n.º 25
0
 public ActionResult Api([Bind(Include = "start,length,search")] RouteValue routeValue)
 {
     ViewBag.routeValue = routeValue;
     return(View());
 }
Ejemplo n.º 26
0
 public void Save(RouteValue routeValue)
 {
     routeRepository.Save(routeValue);
 }