コード例 #1
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ComputerTypeModel model = db.ComputerTypes.Single(x => x.Id == id);

            if (model == null)
            {
                return(HttpNotFound());
            }
            return(PartialView("_PartialDetails", model));
        }
コード例 #2
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ComputerTypeModel computerTypeModel = db.ComputerTypes.Find(id);

            if (computerTypeModel == null)
            {
                return(HttpNotFound());
            }
            return(PartialView(computerTypeModel));
        }
コード例 #3
0
        public ActionResult Delete(int id)
        {
            ComputerTypeModel computerTypeModel = db.ComputerTypes.Find(id);

            try
            {
                // Delete the image drom filesystem.
                string file = Server.MapPath("~" + computerTypeModel.ImagePath);
                System.IO.File.Delete(file);
            }
            catch (Exception) { }
            db.ComputerTypes.Remove(computerTypeModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
ファイル: ComputerTypeAppService.cs プロジェクト: radtek/Fms
        /// <summary>
        /// 更新和新增终端类型
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public ComputerTypeModel InsertOrUpdateComputerType(ComputerTypeModel input)
        {
            if (_ComputerTypeCase.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name))
            {
                throw new UserFriendlyException("名为【" + input.Name + "】的对象已存在!");
            }
            //var entObj =input.MapTo<ComputerType>();
            var entObj = _ComputerTypeCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new ComputerType();

            entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList());
            //var entObj= AutoMapper.Mapper.Map<ComputerType>(input);
            var resObj = _ComputerTypeCase.InsertOrUpdate(entObj);

            if (resObj == null)
            {
                throw new UserFriendlyException("新增或更新失败!");
            }
            else
            {
                return(resObj.MapTo <ComputerTypeModel>());
            }
        }
コード例 #5
0
        public ActionResult Edit(ScheduledModel model)
        {
            if (ModelState.IsValid)
            {
                bool valid = true;
                // Get info
                if (model.Type == ScheduledType.Individual)
                {
                    try
                    {
                        List <int> clist = JsonConvert.DeserializeObject <List <int> >(model.JsonComputerList);
                        if (clist.Count == 0)
                        {
                            ModelState.AddModelError(String.Empty, "The computer list cannot be empty.");
                            valid = false;
                        }

                        try
                        {
                            string names = "|";
                            foreach (var id in clist)
                            {
                                names += ", " + db.Computers.SingleOrDefault(x => x.Id == id).Name;
                            }
                            model.ComputerListNames = names.Replace("|, ", "");
                        }
                        catch (Exception)
                        {
                        }
                    }
                    catch (Exception)
                    {
                        ModelState.AddModelError(String.Empty, "The computer list cannot be empty.");
                        valid = false;
                    }
                }
                if (model.Type == ScheduledType.Color)
                {
                    model.JsonComputerList = "";
                    if (model.ColorId == 0)
                    {
                        ModelState.AddModelError(String.Empty, "Plese select a color.");
                        valid = false;
                    }

                    try
                    {
                        string     names = "|";
                        ColorModel item  = db.Colors.Include(x => x.Computers).SingleOrDefault(x => x.Id == model.ColorId);
                        foreach (var computer in item.Computers)
                        {
                            names += ", " + computer.Name;
                        }
                        model.ComputerListNames = names.Replace("|, ", "");
                    }
                    catch (Exception)
                    {
                    }
                }
                if (model.Type == ScheduledType.Location)
                {
                    model.JsonComputerList = "";
                    if (model.LocationId == 0)
                    {
                        ModelState.AddModelError(String.Empty, "Plese select a location.");
                        valid = false;
                    }

                    try
                    {
                        string        names = "|";
                        LocationModel item  = db.Locations.Include(x => x.Computers).SingleOrDefault(x => x.Id == model.LocationId);
                        foreach (var computer in item.Computers)
                        {
                            names += ", " + computer.Name;
                        }
                        model.ComputerListNames = names.Replace("|, ", "");
                    }
                    catch (Exception)
                    {
                    }
                }
                if (model.Type == ScheduledType.Type)
                {
                    model.JsonComputerList = "";
                    if (model.TypeId == 0)
                    {
                        ModelState.AddModelError(String.Empty, "Plese select a Computer Type.");
                        valid = false;
                    }

                    try
                    {
                        string            names = "|";
                        ComputerTypeModel item  = db.ComputerTypes.Include(x => x.Computers).SingleOrDefault(x => x.Id == model.TypeId);
                        foreach (var computer in item.Computers)
                        {
                            names += ", " + computer.Name;
                        }
                        model.ComputerListNames = names.Replace("|, ", "");
                    }
                    catch (Exception)
                    {
                    }
                }

                if (valid)
                {
                    // Event
                    SysEvent ev = new SysEvent();
                    ev.Action       = Enums.Action.Info;
                    ev.Description  = "Edited schedule: " + model.Name;
                    ev.ActionStatus = ActionStatus.OK;
                    LogsController.AddEvent(ev, User.Identity.GetUserId());

                    model.LastRun         = DateTime.Now.AddYears(-100);
                    db.Entry(model).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(model));
                }
            }
            return(View(model));
        }
コード例 #6
0
        public ActionResult Create(ScheduledModel model)
        {
            ModelState.Clear();
            bool valid = model.Name != null;

            model.LastRun = DateTime.Now.AddYears(-100);
            if (!valid)
            {
                ModelState.AddModelError(String.Empty, "Name cannot be empty.");
            }


            if (model.Type == ScheduledType.Individual)
            {
                try
                {
                    List <int> clist = JsonConvert.DeserializeObject <List <int> >(model.JsonComputerList);
                    if (clist.Count == 0)
                    {
                        ModelState.AddModelError(String.Empty, "The computer list cannot be empty.");
                        valid = false;
                    }

                    try
                    {
                        string names = "|";
                        foreach (var id in clist)
                        {
                            names += ", " + db.Computers.SingleOrDefault(x => x.Id == id).Name;
                        }
                        model.ComputerListNames = names.Replace("|, ", "");
                    }
                    catch (Exception)
                    {
                    }
                }
                catch (Exception)
                {
                    ModelState.AddModelError(String.Empty, "The computer list cannot be empty.");
                    valid = false;
                }
            }
            if (model.Type == ScheduledType.Color)
            {
                model.JsonComputerList = "";
                if (model.ColorId == 0)
                {
                    ModelState.AddModelError(String.Empty, "Plese select a color.");
                    valid = false;
                }

                try
                {
                    string     names = "|";
                    ColorModel item  = db.Colors.Include(x => x.Computers).SingleOrDefault(x => x.Id == model.ColorId);
                    foreach (var computer in item.Computers)
                    {
                        names += ", " + computer.Name;
                    }
                    model.ComputerListNames = names.Replace("|, ", "");
                }
                catch (Exception)
                {
                }
            }
            if (model.Type == ScheduledType.Location)
            {
                model.JsonComputerList = "";
                if (model.LocationId == 0)
                {
                    ModelState.AddModelError(String.Empty, "Plese select a location.");
                    valid = false;
                }

                try
                {
                    string        names = "|";
                    LocationModel item  = db.Locations.Include(x => x.Computers).SingleOrDefault(x => x.Id == model.LocationId);
                    foreach (var computer in item.Computers)
                    {
                        names += ", " + computer.Name;
                    }
                    model.ComputerListNames = names.Replace("|, ", "");
                }
                catch (Exception)
                {
                }
            }
            if (model.Type == ScheduledType.Type)
            {
                model.JsonComputerList = "";
                if (model.TypeId == 0)
                {
                    ModelState.AddModelError(String.Empty, "Plese select a Computer Type.");
                    valid = false;
                }

                try
                {
                    string            names = "|";
                    ComputerTypeModel item  = db.ComputerTypes.Include(x => x.Computers).SingleOrDefault(x => x.Id == model.TypeId);
                    foreach (var computer in item.Computers)
                    {
                        names += ", " + computer.Name;
                    }
                    model.ComputerListNames = names.Replace("|, ", "");
                }
                catch (Exception)
                {
                }
            }

            if (valid)
            {
                db.Schedules.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                ViewBag.Hours = new List <int>()
                {
                    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
                };
                ViewBag.Minutes = new List <int>()
                {
                    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
                    21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
                    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59
                };
                return(View(model));
            }
        }