public ActionResult Edit(IEnumerable<HttpPostedFileBase> SecilenDosyalar, string Acıklama, int? secimil, int? secimilce, int? secimMahalle, [Bind(Include = "ID,ADVERTDATE,ROOMCOUNTID,FLOORID,HEATINGID,EXPLANATION,TITLE,BATHCOUNT,COST,PERSONCOUNT,ATYPEID,BALCONY,GARDEN,CONSTRUCTIONDATE,ADDRESSID,MONTHLYFEE,FULLYFURNISHED,SQUAREFEET,TYPID,OWNERID,TIMEID,OTHER")] Advert advert) { var city = te.tbl_il; ViewBag.City = new SelectList(city, "il_id", "il_ad"); var town = te.tbl_ilce; ViewBag.townn = new SelectList(town, "ilce_id", "ilce_ad"); var district = te.tbl_mahalle; ViewBag.dstrct = new SelectList(district, "mahalle_id", "mahalle_ad"); if (ModelState.IsValid) { Guid oid = Guid.NewGuid(); foreach (var insider in db.Insider) { if (insider.EMAIL == User.Identity.Name) { oid = insider.ID; ViewBag.Telefon = insider.PHONENUMBER; ViewBag.AID = insider.ID; } } Address adres = new Address(); if (secimil != null || secimilce != null || secimMahalle != null) { adres.CITYID = secimil; adres.DISTRICTID = secimMahalle; adres.TOWNID = secimilce; adres.EXPLANATION = Acıklama; adres.ID = Guid.NewGuid(); advert.ADDRESSID = adres.ID; db.Address.Add(adres); } if (SecilenDosyalar != null) { var images = Server.MapPath("/Images"); DirectoryInfo di = new DirectoryInfo(images); FileInfo[] rgFiles = di.GetFiles(); foreach (var rsm in rgFiles) { string name = rsm.Name; var isim = rsm.Name.Split(','); if (isim[0].ToString() == advert.ID.ToString()) { System.IO.File.Delete(Server.MapPath("~/Images/" + name)); } } foreach (var file in SecilenDosyalar) { say++; file.SaveAs(HttpContext.Server.MapPath("~/Images/" + advert.ID + "," + say + ".jpg")); } } advert.OWNERID = oid; db.Entry(advert).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index/" + oid); } ViewBag.ADDRESSID = new SelectList(db.Address, "ID", "EXPLANATION", advert.ADDRESSID); ViewBag.ATYPEID = new SelectList(db.AdvertType, "ID", "NAME", advert.ATYPEID); ViewBag.FLOORID = new SelectList(db.ApartmentFloor, "ID", "NAME", advert.FLOORID); ViewBag.TIMEID = new SelectList(db.DeliveryTime, "ID", "NAME", advert.TIMEID); ViewBag.HEATINGID = new SelectList(db.Heating, "ID", "NAME", advert.HEATINGID); ViewBag.OWNERID = new SelectList(db.Insider, "ID", "NAME", advert.OWNERID); ViewBag.ROOMCOUNTID = new SelectList(db.RoomCount, "ID", "NAME", advert.ROOMCOUNTID); ViewBag.TYPID = new SelectList(db.Type, "ID", "NAME", advert.TYPID); return View(advert); }
public async Task<ActionResult> Register(RegisterViewModel model,string Acıklama, int? secimil, int? secimilce, int? secimMahalle, [Bind(Include = "ID,NAME,EMAIL,PHONENUMBER,PASSWORD,BIRTHDATE,GENDER,ADDRESSID,SURNAME,CONFIRMPASSWORD")] Insider insider) { var city = te.tbl_il; ViewBag.City = new SelectList(city, "il_id", "il_ad"); var town = te.tbl_ilce; ViewBag.townn = new SelectList(town, "ilce_id", "ilce_ad"); var district = te.tbl_mahalle; ViewBag.dstrct = new SelectList(district, "mahalle_id", "mahalle_ad"); if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, }; insider.ID = Guid.NewGuid(); Address adres = new Address(); if(secimil!=null || secimilce!=null || secimMahalle!=null) { adres.CITYID = secimil; adres.DISTRICTID = secimMahalle; adres.TOWNID = secimilce; adres.EXPLANATION = Acıklama; adres.ID = Guid.NewGuid(); insider.ADDRESSID = adres.ID; db.Address.Add(adres); } db.Insider.Add(insider); db.SaveChanges(); Session["user_id"] = insider.ID; return RedirectToAction("Index", "Advert", new { insertid = insider.ID }); } return View(); }