public async Task <IActionResult> PutEmployee(int id, Employee employee)
        {
            if (id != employee.EmployeeId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "ID,Name")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,ParentRegionID")] ListingRegion listingRegion)
 {
     if (ModelState.IsValid)
     {
         db.Entry(listingRegion).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ParentRegionID = new SelectList(db.ListingRegions, "ID", "Name", listingRegion.ParentRegionID);
     return(View(listingRegion));
 }
Exemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "ID,Title,Description,Address,Phone1,Phone2,Website,Lat,Long,VideoUrl,FacebookUrl,TwitterUrl,YoutubeUrl,PinterestUrl,SubmittedBy,ConfirmedBy,SubmitDate,ConfirmDate,CategoryID,ListingRegionID")] Venue venue)
 {
     if (ModelState.IsValid)
     {
         db.Entry(venue).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryID      = new SelectList(db.Categories, "ID", "Name", venue.CategoryID);
     ViewBag.ListingRegionID = new SelectList(db.ListingRegions, "ID", "Name", venue.ListingRegionID);
     return(View(venue));
 }
Exemplo n.º 5
0
        static async void TestUpdate()
        {
            using (var db = new DALContext())
            {
                var oldI = await db.IceCreams.FindAsync(4);

                var newI = oldI;

                newI.Name = "IKEA 222";
                db.Entry(oldI).CurrentValues.SetValues(newI);
                await db.SaveChangesAsync();
            }
        }
Exemplo n.º 6
0
        static async void Update()
        {
            using (var db = new DALContext())
            {
                var ice = db.IceCreams.First();

                Console.WriteLine("Avant ");
                Console.WriteLine($"{ice.Name} {ice.Description}");

                var newIce = ice;

                newIce.Description = "Une nouvelle description";
                newIce.AverageRate = 4;

                db.Entry(ice).CurrentValues.SetValues(newIce);
                await db.SaveChangesAsync();

                var icen = db.IceCreams.First();
                Console.WriteLine($"{icen.Name} {icen.Description}");
            }
        }
Exemplo n.º 7
0
 public void Update(T item)
 {
     db.Entry(item).State = EntityState.Modified;
 }
Exemplo n.º 8
0
        public IActionResult Edit(ICollection <Microsoft.AspNet.Http.IFormFile> Productphoto_file, Album model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (Productphoto_file.Count > 0)
                    {
                        foreach (var file in Productphoto_file)
                        {
                            if (file.Length > 1024 * 1024)
                            {
                                TempData["ErrorMessage"] = "حجم فایل انتخاب شده بیش از یک مگابایت است. لطفا فایل دیگری انتخاب نمایید";

                                break;
                            }
                            else if (file.Length == 0)
                            {
                                TempData["ErrorMessage"] = "حجم فایل انتخاب شده صفر بایت است. لطفا فایل دیگری انتخاب نمایید";

                                break;
                            }
                            else
                            {
                                var fileName = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');

                                using (Stream sr = file.OpenReadStream())
                                {
                                    byte[] fileData = null;
                                    using (MemoryStream msOrig = Utils.LoadToMemoryStream(sr))
                                    {
                                        // resize it
                                        // todo: we always resize profile image to 140x140
                                        Image        img = Bitmap.FromStream(msOrig);
                                        Bitmap       bmp = new Bitmap(img, new Size(340, 280));
                                        MemoryStream ms  = new MemoryStream();
                                        bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);



                                        // read content instead
                                        fileData = Utils.ConvertMemoryStreamToBytes(ms);

                                        ms.Dispose();
                                        bmp.Dispose();
                                        img.Dispose();
                                    }

                                    /*
                                     * // remove error flags
                                     * //TempData.Remove("ErrorMessage");
                                     * AssetData = new Byte[fileData.Length];
                                     *
                                     * AssetType= "jpg";
                                     * Buffer.BlockCopy(fileData, 0, AssetData, 0, fileData.Length);
                                     *
                                     *
                                     * ViewBag.up = Utils.GenerateHttpResponseImageOntheFly(AssetData, "jpg");
                                     *
                                     * // just one file!
                                     * // break;
                                     */

                                    //_db = new DALContext();
                                    Models.Album Album = new Models.Album();
                                    Album.AssetData = new Byte[fileData.Length];
                                    Album.AssetType = "jpg";
                                    Buffer.BlockCopy(fileData, 0, Album.AssetData, 0, fileData.Length);

                                    ViewBag.imgusedatabaseController = Album.AssetData;//for img usedatabaseController

                                    Album.Titel = model.Titel;

                                    Album.Id = model.Id;
                                    _db.Entry(Album).State = Microsoft.Data.Entity.EntityState.Modified;
                                    _db.SaveChanges();

                                    TempData["ErrorMessage"] = " ویرایش انجام شد";
                                }
                            }
                        }
                    }
                    else
                    {
                        //_db = new DALContext();
                        Models.Album a = _db.Albums.FirstOrDefault(x => x.Id == model.Id);


                        a.Titel = model.Titel;
                        _db.SaveChanges();
                        TempData["ErrorMessage"] = "ویرایش انجام شد";
                    }
                }
                else
                {
                    TempData["ErrorMessage"] = "لطفا یک عکس انتخاب کنید و عنوان را وارد نمایید ";
                }

                //return RedirectToAction("ShowAlbums");
                //return View();
                return(RedirectToAction("Edit", model.Id));
            }
            catch (Exception ex)
            {
                return(RedirectToAction(nameof(HomeController.Error), "Home"));
            }
        }