예제 #1
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Description,Units_Id,ForSale,SellPrice,Notes")] ServicesModels servicesModels)
        {
            var check = db.Services.AsNoTracking().Where(x =>
                                                         x.Description == servicesModels.Description &&
                                                         x.Units_Id == servicesModels.Units_Id).ToList();

            if (check.Count > 0)
            {
                ModelState.AddModelError("Duplicate", "This Service already existed.");
            }

            if (ModelState.IsValid)
            {
                servicesModels.Id     = Guid.NewGuid();
                servicesModels.Active = true;
                db.Services.Add(servicesModels);

                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.listUnit = new SelectList(db.Units.Where(x => x.Active == true).OrderBy(x => x.Name), "Id", "Name");
            return(View(servicesModels));
        }
예제 #2
0
        public async Task <ActionResult> Edit(Guid?id)
        {
            Permission p    = new Permission();
            bool       auth = p.IsGranted(User.Identity.Name, this.ControllerContext.RouteData.Values["controller"].ToString() + "_" + this.ControllerContext.RouteData.Values["action"].ToString());

            if (!auth)
            {
                return(new ViewResult()
                {
                    ViewName = "Unauthorized"
                });
            }
            else
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                ServicesModels servicesModels = await db.Services.FindAsync(id);

                if (servicesModels == null)
                {
                    return(HttpNotFound());
                }
                ViewBag.listUnit = new SelectList(db.Units.Where(x => x.Active == true).OrderBy(x => x.Name), "Id", "Name");
                return(View(servicesModels));
            }
        }
예제 #3
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Description,Units_Id,ForSale,SellPrice,Notes,Active")] ServicesModels servicesModels)
        {
            var check = db.Services.AsNoTracking().Where(x =>
                                                         x.Id != servicesModels.Id &&
                                                         x.Description == servicesModels.Description &&
                                                         x.Units_Id == servicesModels.Units_Id).ToList();

            if (check.Count > 0)
            {
                ModelState.AddModelError("Duplicate", "This Service already existed.");
            }

            if (ModelState.IsValid)
            {
                var current_data = await db.Services.FindAsync(servicesModels.Id);

                current_data.Description     = servicesModels.Description;
                current_data.Units_Id        = servicesModels.Units_Id;
                current_data.ForSale         = servicesModels.ForSale;
                current_data.SellPrice       = servicesModels.SellPrice;
                current_data.Notes           = servicesModels.Notes;
                current_data.Active          = servicesModels.Active;
                db.Entry(current_data).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.listUnit = new SelectList(db.Units.Where(x => x.Active == true).OrderBy(x => x.Name), "Id", "Name");
            return(View(servicesModels));
        }
        // GET: Services/Edit/5
        public ActionResult Edit(int id)
        {
            Service        s       = ss.GetById(id);
            ServicesModels Service = new ServicesModels();

            Service.TypeService = s.TypeService;
            Service.NbrEmployee = s.NbrEmployee;


            return(View(Service));
        }
        public ActionResult Edit(int id, ServicesModels collection)
        {
            Service s = ss.GetById(id);

            s.TypeService = collection.TypeService;
            s.NbrEmployee = collection.NbrEmployee;

            ss.Update(s);
            ss.Commit();


            return(RedirectToAction("Index"));
        }
        // GET: Services
        public ActionResult Index()
        {
            List <ServicesModels> list = new List <ServicesModels>();

            foreach (var s in ss.GetAll())
            {
                ServicesModels sm = new ServicesModels();
                sm.idService   = s.idService;
                sm.TypeService = s.TypeService;
                sm.NbrEmployee = s.NbrEmployee;
                list.Add(sm);
            }
            return(View(list));
        }
        public ActionResult Create(ServicesModels collection)
        {
            //try
            //{
            Service s = new Service();

            s.TypeService = collection.TypeService;
            s.NbrEmployee = collection.NbrEmployee;
            ss.Add(s);
            ss.Commit();
            return(RedirectToAction("Index"));
            //}
            //catch
            //{
            //return View();
            //}
        }