コード例 #1
0
        public ActionResult Edit(ProductViewModel productViewModel)
        {
            productViewModel.ItemList = db.Citys.ToList().ConvertAll(
                a =>
            {
                return(new SelectListItem()
                {
                    Text = a.Name,
                    Value = a.Id.ToString(),
                    Selected = false
                });
            });
            var item = db.Entry(productViewModel.Product);

            item.State = EntityState.Modified;
            item.Collection(i => i.Drugstores).Load();
            productViewModel.Product.Drugstores.Clear();

            foreach (var id in productViewModel._selectedProductDrugstore)
            {
                productViewModel.Product.Drugstores.Add(db.Drugstores.First(i => i.Id == id));
            }

            if (ModelState.IsValid)
            {
                db.Entry(productViewModel.Product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productViewModel));
        }
コード例 #2
0
        public ActionResult Edit(DrugstoreViewModel drugstoreViewModel)
        {
            drugstoreViewModel.ListItems = db.Citys.ToList().ConvertAll(
                a =>
            {
                return(new SelectListItem()
                {
                    Text = a.Name,
                    Value = a.Id.ToString(),
                    Selected = false
                });
            });
            var item = db.Entry <Drugstore>(drugstoreViewModel.Drugstore);

            item.State = EntityState.Modified;
            item.Collection(i => i.Products).Load();
            drugstoreViewModel.Drugstore.Products.Clear();

            foreach (var id in drugstoreViewModel._selectedDrugstoreProduct)
            {
                drugstoreViewModel.Drugstore.Products.Add(db.Products.First(i => i.Id == id));
            }

            if (ModelState.IsValid)
            {
                db.Entry(drugstoreViewModel.Drugstore).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(drugstoreViewModel));
        }
コード例 #3
0
        public async Task Atualizar(int id, T Entity)
        {
            var produtoBD = await ObterId(id);

            _context.Entry(produtoBD).CurrentValues.SetValues(Entity);
            _context.Entry(produtoBD).State = EntityState.Modified;

            await _context.SaveChangesAsync();
        }
コード例 #4
0
ファイル: BaseService.cs プロジェクト: weqan/NewWq
        public async Task EditAsync(T model, bool saved = true)
        {
            _db.Entry(model).State = System.Data.Entity.EntityState.Modified;
            if (saved)
            {
                //SaveChanges前先关闭验证实体有效性(ValidateOnSaveEnabled)这个开关
                _db.Configuration.ValidateOnSaveEnabled = false;
                await _db.SaveChangesAsync();

                _db.Configuration.ValidateOnSaveEnabled = true;
            }
        }
コード例 #5
0
        /// <summary>
        /// Deletes an item
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>string</returns>
        ///


        public async Task <string> Delete(TEntity entity)
        {
            try
            {
                _context.Entry(entity).State = EntityState.Deleted;
                await _context.SaveChangesAsync();

                return("Success");
            }
            catch (Exception er)
            {
                return(er.Message);
            }
        }
コード例 #6
0
        public async Task<IActionResult> PutMatiere(int id, Matiere matiere)
        {
            if (id != matiere.Id)
            {
                return BadRequest();
            }

            _context.Entry(matiere).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MatiereExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }
コード例 #7
0
        public async Task <IActionResult> PutClassroom(int id, Classroom classroom)
        {
            if (id != classroom.Id)
            {
                return(BadRequest());
            }

            _context.Entry(classroom).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClassroomExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #8
0
 public ActionResult Edit([Bind(Include = "ID,Type,Result,Patient_ID")] Checkup checkup)
 {
     if (User.Identity.IsAuthenticated)
     {
         string cid = User.Identity.GetUserId();
         UserManager <ApplicationUser> userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(appDb));
         var roles = userManager.GetRoles(cid);
         if (roles[0] == "Doctor")
         {
             if (ModelState.IsValid)
             {
                 db.Entry(checkup).State = EntityState.Modified;
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
             return(View(checkup));
         }
         else
         {
             return(View("AccessDenied"));
         }
     }
     else
     {
         return(View("NotLoggedIn"));
     }
 }
コード例 #9
0
ファイル: AboutUsController.cs プロジェクト: tobi5703/VHAPI
        public async Task <IActionResult> PutAboutUs(int id, AboutUs aboutUs)
        {
            if (id != aboutUs.Id)
            {
                return(BadRequest());
            }

            _context.Entry(aboutUs).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AboutUsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #10
0
        // PUT api/Laptop/5
        public async Task <IHttpActionResult> PutLaptop(string id, Laptop laptop)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != laptop.ID)
            {
                return(BadRequest());
            }

            db.Entry(laptop).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LaptopExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #11
0
ファイル: OrderController.cs プロジェクト: volgan/Web-API
        // PUT api/Order/5
        public async Task <IHttpActionResult> PutOrder(int id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != order.OrderID)
            {
                return(BadRequest());
            }

            db.Entry(order).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #12
0
        // PUT api/Customer/5
        public async Task <IHttpActionResult> PutCustomer(long id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            customer.Password = getSHA256Hash(customer.Password);
            if (id != customer.CustomerID)
            {
                return(BadRequest());
            }

            db.Entry(customer).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #13
0
        public IHttpActionResult Comment(int id, Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.CommentID)
            {
                return(BadRequest());
            }

            db.Entry(comment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #14
0
ファイル: settingController.cs プロジェクト: khanhlive/NDK
        public ActionResult TamNhinSuMenhPOST(SystemConfig model)
        {
            using (WebContext db = new WebContext())
            {
                int  _loai   = (int)WebsiteCategory.TamNhinSuMenh;
                bool hasSoDo = db.SystemConfigs.Any(p => p.Category == _loai);

                if (hasSoDo)
                {
                    //update
                    var obj = db.SystemConfigs.AsNoTracking().FirstOrDefault(p => p.Category == _loai);
                    obj.Name    = model.Name;
                    obj.Content = model.Content;
                    db.Entry <SystemConfig>(obj).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    //insert
                    model.Status   = 1;
                    model.Category = (int)WebsiteCategory.TamNhinSuMenh;
                    db.SystemConfigs.Add(model);
                }
                int count = db.SaveChanges();
                if (count >= 0)
                {
                    TempData["message"] = "Chỉnh sửa thông tin thành công";
                    return(RedirectToAction("TamNhinSuMenh"));
                }
                else
                {
                    TempData["message"] = "Không chỉnh sửa được thông tin";
                    return(View("TamNhinSuMenh"));
                }
            }
        }
コード例 #15
0
        public async Task <IActionResult> PutReview(int id, Review review)
        {
            if (id != review.Id)
            {
                return(BadRequest());
            }

            _context.Entry(review).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReviewExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #16
0
 public void Update(Task item)
 {
     using (var context = new WebContext())
     {
         context.Entry(item).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #17
0
 public ActionResult Edit(Gente gente)
 {
     if (ModelState.IsValid)
     {
         db.Entry(gente).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(gente));
 }
コード例 #18
0
 public ActionResult Edit([Bind(Include = "ID,restName,restType,restCity,restAddress,restRating,restPrice,restKosher,restInfo,imgRest1,imgRest2,imgRest3,imgRest4,imgRest5")] Rest rest)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rest).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(rest));
 }
コード例 #19
0
 public ActionResult Edit([Bind(Include = "id,sales_type,tax_included,factor,inactive")] SalesType salesType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(salesType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(salesType));
 }
コード例 #20
0
 public ActionResult Edit([Bind(Include = "id,type,name,description,inactive")] DimensionTag dimensionTag)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dimensionTag).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(dimensionTag));
 }
コード例 #21
0
 public ActionResult Edit([Bind(Include = "ID,hotelName,hotelCity,hotelAddress,hotelRating,hotelPrice,Wifi,hotelTransportation,imghotel1,imghotel2,imghotel3,imghotel4,imghotel5,hotelInfo")] Hotel hotel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hotel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(hotel));
 }
コード例 #22
0
 public ActionResult Edit([Bind(Include = "ID,Title,Description,ReleaseTime,ArticleText,ImageFile")] Articles articles)
 {
     if (ModelState.IsValid)
     {
         db.Entry(articles).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(articles));
 }
コード例 #23
0
 public ActionResult Edit([Bind(Include = "ID,Code,Name,Price,Category")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
コード例 #24
0
 public ActionResult Edit([Bind(Include = "ID,Title,ReleaseDate,Price,Description,ImageFile,genre")] Games games)
 {
     if (ModelState.IsValid)
     {
         db.Entry(games).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(games));
 }
コード例 #25
0
 public ActionResult Edit([Bind(Include = "id,description,inactive")] SalesGroups salesGroups)
 {
     if (ModelState.IsValid)
     {
         db.Entry(salesGroups).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(salesGroups));
 }
コード例 #26
0
 public ActionResult Edit([Bind(Include = "ID,Name")] GameDevelopers gameDevelopers)
 {
     if (ModelState.IsValid)
     {
         db.Entry(gameDevelopers).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(gameDevelopers));
 }
コード例 #27
0
 public ActionResult Edit([Bind(Include = "Id,Name")] City city)
 {
     if (ModelState.IsValid)
     {
         db.Entry(city).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(city));
 }
コード例 #28
0
 public ActionResult Edit([Bind(Include = "Id,Name1,Composition1,Mass1,Name2,Composition2,Mass2,Name3,Composition3,Mass3,Name4,Composition4,Mass4,ProductId")] AnalogousProduct analogousProduct)
 {
     if (ModelState.IsValid)
     {
         db.Entry(analogousProduct).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", analogousProduct.ProductId);
     return(View(analogousProduct));
 }
コード例 #29
0
        public async Task <ActionResult> Edit([Bind(Include = "StudentId,FirstName,LastName")] Student student)
        {
            if (ModelState.IsValid)
            {
                db.Entry(student).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(student));
        }
コード例 #30
0
 public ActionResult Edit([Bind(Include = "ID,HotelID,recoName,recoPhone,recoRating,recoInfo")] RecommendationHotel recommendationHotel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(recommendationHotel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.HotelID = new SelectList(db.hotels, "ID", "hotelName", recommendationHotel.HotelID);
     return(View(recommendationHotel));
 }