Beispiel #1
0
        //ToanTXSE
        //Get box List by location ID
        public static List <Models.AndroidBoxVM> GetBoxIdByBrandId()
        {
            IBoxService      boxService      = DependencyUtils.Resolve <IBoxService>();
            ILocationService locationService = DependencyUtils.Resolve <ILocationService>();
            var           AndroidBoxVM       = new List <Models.AndroidBoxVM>();
            IBrandService brandService       = DependencyUtils.Resolve <IBrandService>();
            var           user    = Helper.GetCurrentUser();
            var           boxList = boxService.GetBoxIdByBrandId(user.BrandID);

            foreach (var item in boxList)
            {
                var location       = locationService.Get(item.LocationID);
                var locationString = location.Address + ", Quận " + location.District + ", TP." + location.Province;
                var m = new Models.AndroidBoxVM
                {
                    Name        = item.BoxName,
                    Description = item.Description,
                    BoxId       = item.BoxID,
                    LocationId  = item.LocationID,
                    Location    = locationString,
                };
                AndroidBoxVM.Add(m);
            }
            return(AndroidBoxVM);
        }
Beispiel #2
0
        // GET: AndroidBox/Form/:id
        public ActionResult Form(int?id)
        {
            Models.AndroidBoxVM model = null;

            if (id != null)
            {
                var box = this.boxService.Get(id);
                if (box != null)
                {
                    model = new Models.AndroidBoxVM
                    {
                        Name        = box.BoxName,
                        Description = box.Description,
                        BoxId       = box.BoxID,
                        LocationId  = box.LocationID
                    };
                }
            }
            ViewBag.locationList = LocationController.GetLocationIdByBrandId();
            return(View(model));
        }
Beispiel #3
0
        public async System.Threading.Tasks.Task <ActionResult> Add(Models.AndroidBoxVM model)
        {
            if (ModelState.IsValid)
            {
                var box = new Data.Models.Entities.Box
                {
                    BoxName     = model.Name,
                    Description = model.Description,
                    LocationID  = model.LocationId
                };
                await this.boxService.CreateAsync(box);

                //return this.RedirectToAction("Index");
                Session.Clear();
                Session["ADD_RESULT"] = true;
                return(new ContentResult
                {
                    Content = string.Format("<script type='text/javascript'>window.parent.location.href = '{0}';</script>", Url.Action("Index", "AndroidBox")),
                    ContentType = "text/html"
                });
            }
            return(View("Form", model));
        }
Beispiel #4
0
        public async System.Threading.Tasks.Task <ActionResult> Update(Models.AndroidBoxVM model)
        {
            if (ModelState.IsValid)
            {
                var box = this.boxService.Get(model.BoxId);
                if (box != null)
                {
                    box.BoxName     = model.Name;
                    box.Description = model.Description;
                    box.LocationID  = model.LocationId;
                }
                await this.boxService.UpdateAsync(box);

                Session.Clear();
                Session["UPDATE_RESULT"] = true;
                return(new ContentResult
                {
                    Content = string.Format("<script type='text/javascript'>window.parent.location.href = '{0}';</script>", Url.Action("Index", "AndroidBox")),
                    ContentType = "text/html"
                });
            }
            return(View("Form", model));
        }
        public JsonResult ReceiveLocationId(string id)
        {
            int locationId = Int32.Parse(id);

            try
            {
                //get box list by location ID
                IBoxService    boxService    = DependencyUtils.Resolve <IBoxService>();
                IDeviceService deviceService = DependencyUtils.Resolve <IDeviceService>();
                IMapper        mapper        = DependencyUtils.Resolve <IMapper>();
                var            boxs          = boxService.Get().ToList();
                var            boxVMs        = new List <Models.AndroidBoxVM>();

                foreach (var item in boxs)
                {
                    //check boxID is being matched
                    if (deviceService.Get(a => a.BoxID == item.BoxID).FirstOrDefault() == null)
                    {
                        if (item.LocationID == locationId)
                        {
                            var b = new Models.AndroidBoxVM
                            {
                                Name        = item.BoxName,
                                Description = item.Description,
                                BoxId       = item.BoxID,
                                LocationId  = item.LocationID,
                            };
                            boxVMs.Add(b);
                        }
                    }
                }
                IScreenService screenService = DependencyUtils.Resolve <IScreenService>();
                var            screens       = screenService.Get().ToList();
                var            screenVMs     = new List <Models.ScreenVM>();
                foreach (var item in screens)
                {
                    //check boxID is being matched
                    if (deviceService.Get(a => a.ScreenID == item.ScreenID).FirstOrDefault() == null)
                    {
                        if (item.LocationID == locationId)
                        {
                            var b = new Models.ScreenVM
                            {
                                Name         = item.ScreenName,
                                Description  = item.Description,
                                ScreenId     = item.ScreenID,
                                LocationId   = item.LocationID,
                                isHorizontal = item.isHorizontal,
                            };
                            screenVMs.Add(b);
                        }
                    }
                }
                return(Json(new
                {
                    boxListByLocationId = boxVMs,
                    screenListByLocationId = screenVMs
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }