Ejemplo n.º 1
0
        ////approve the advertisement by detail
        //public ActionResult PassByDetail(Advertisement advertisement) {
        //    if (advertisement != null)
        //    {
        //        //?? need find again or other method to update?????
        //        advertisement = db.Advertisements.Find(advertisement.ID);
        //        advertisement.Pass = 1;
        //        db.Advertisements.Add(advertisement);
        //        db.SaveChanges();
        //        return RedirectToAction("Index");
        //    }
        //    return View();
        //}

        //approve the advertisement by main page
        public ActionResult Pass(string id)
        {
            if (id != null && !id.Equals(""))
            {
                Advertisement advertisement = db.Advertisements.Find(int.Parse(id));
                advertisement.Pass            = 1;
                db.Entry(advertisement).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Ejemplo n.º 2
0
        public IActionResult Put([FromODataUri] int key, [FromBody] Interior entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (entity.DefinitionID == 0)
            {
                ModelState.AddModelError <Interior>(e => e.Definition, "Could not determine type of interior, please specify the type.");
                return(BadRequest(ModelState));
            }

            if (entity.ID == 0)
            {
                entity.ID = key;
            }

            if (key != entity.ID)
            {
                return(BadRequest());
            }

            _context.Entry(entity).State = EntityState.Modified;
            _context.SaveChanges();
            return(Updated(entity));
        }
        public async Task <IActionResult> PutHouse(int id, House house)
        {
            if (id != house.id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 4
0
 public virtual async Task <int> UpdateModel(T model)
 {
     _logger.LogInformation(@$ "{_serviceName} Update {nameof(T)}", model);
     _context.Entry(model).State = EntityState.Modified;
     _logger.LogInformation(@$ "{_serviceName} Update {nameof(T)} complete", model);
     return(await _context.SaveChangesAsync());
 }
 public ActionResult Edit([Bind(Include = "ID,Username,Password,Birthday")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(student));
 }
Ejemplo n.º 6
0
        public async Task <ServiceResponse> UpdateCounter(CounterViewModel model)
        {
            _logger.LogInformation(@$ "{_serviceName} Update {nameof(Counter)}", model);
            _context.Entry(model).State = EntityState.Modified;
            _logger.LogInformation(@$ "{_serviceName} Update {nameof(Counter)} complete", model);

            var resultUpdate = await _context.SaveChangesAsync();

            if (resultUpdate == 1)
            {
                return(new ServiceResponse()
                {
                    Status = ServiceResponseStatus.Ok,
                    Result = resultUpdate
                });
            }

            return(new ServiceResponse()
            {
                Status = ServiceResponseStatus.NotFound,
                Result = $"Update {nameof(Counter)} id={model.Id} not found"
            });
        }
Ejemplo n.º 7
0
 public virtual void Update(T entity)
 {
     dbset.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
 }
Ejemplo n.º 8
0
 public async Task EditAsync(House house)
 {
     db.Entry(house).State = EntityState.Modified;
     await SaveAsync();
 }
        //// GET: Landlord/Create
        //public ActionResult Create()
        //{
        //    return View();
        //}


        public ActionResult CreateToDatabase(string description, string title, string address)
        {
            if (HttpContext.Session["ID"] != null && !HttpContext.Session["ID"].ToString().Equals(""))
            {
                //????must set both of two????
                Landlord landlord = db.Landlords.Find((int)HttpContext.Session["ID"]);
                //NULL?????
                Advertisement advertisement = new Advertisement();
                advertisement.Description = description;
                advertisement.Title       = title;
                advertisement.address     = address;
                // System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
                HttpRequest        request = System.Web.HttpContext.Current.Request;
                HttpFileCollection files   = request.Files;
                int s = 3;
                if (files.Count > 0)
                {
                    for (int i = 0; i < files.Count; i++)
                    {
                        HttpPostedFile FileSave = files[i];  //用key获取单个文件对象HttpPostedFile

                        if (FileSave != null && FileSave.FileName.Length > 0)
                        {
                            Image im = new Image
                            {
                                AdvertisementID = landlord.ID,
                                ImageData       = new byte[FileSave.ContentLength],
                                ImageMimeType   = FileSave.ContentType,
                                Description     = Request.Form[s]
                            };
                            FileSave.InputStream.Read(im.ImageData, 0, im.ImageData.Length);
                            if (advertisement.Images == null)
                            {
                                List <Image> imgs = new List <Image>();
                                imgs.Add(im);
                                advertisement.Images = imgs;
                            }
                            else
                            {
                                advertisement.Images.Add(im);
                            }
                        }
                        s++;
                    }
                }


                if (landlord.Advertisements == null)
                {
                    List <Advertisement> advs = new List <Advertisement>();
                    advs.Add(advertisement);
                    landlord.Advertisements = advs;
                }
                else
                {
                    landlord.Advertisements.Add(advertisement);
                }
                db.Entry(landlord).State = EntityState.Modified;
                db.SaveChanges();
                //advertisement.LandlordID = landlord.ID;
                ViewBag.messages = "Submit succefully!";
                return(RedirectToAction("Index", "Landlord"));
            }
            else
            {
                ViewBag.message = "please login in again!";
                return(RedirectToAction("Login", "Login"));
            }
        }
Ejemplo n.º 10
0
 public async Task <ActionResult <int> > UptReHouse([FromBody] Second_House ci)
 {
     db.Entry(ci).State = EntityState.Modified;
     return(await db.SaveChangesAsync());
 }