public ActionResult Create(BillBoard billBoard, HttpPostedFileBase photo) { ViewBag.Company = new SelectList(db.Companies.ToList(), "Id", "Name"); ViewBag.BillBoardType = new SelectList(db.BillBoardTypes.ToList(), "Id", "Name"); //ViewBag.BillBoardSize = new SelectList(db.BillBoardSizes.ToList(), "Id", "Name"); var zoneAndWard = db.ZoneAndWards.FirstOrDefault(); int totalZone = 0; int totalWard = 0; if(zoneAndWard != null) { totalZone = zoneAndWard.TotalZone; } if (zoneAndWard != null) { totalWard = zoneAndWard.TotalWard; } ViewBag.totalZone = totalZone; ViewBag.totalWard = totalWard; var billboardSizes = db.BillBoardSizes.ToList(); var billboardSizeList = billboardSizes.Select(e => new SelectListItem() { Text=string.Format("{0} X {1}",e.Height,e.Width),Value=e.ID.ToString()}); ViewBag.BillBoardSize = billboardSizeList; var taxRanges = db.TaxRanges.ToList(); var taxRangeDDL= taxRanges.Select(e => new SelectListItem() { Text = string.Format("{0} - {1}", e.TaxFrom, e.TaxTo), Value = e.ID.ToString() }); ViewBag.TaxRange = taxRangeDDL; if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); string photoId = Guid.NewGuid().ToString() + Path.GetExtension(fileName); var path = Path.Combine(Server.MapPath("~/Images/"), photoId); file.SaveAs(path); } } if (ModelState.IsValid) { var billboardWithGeneratedKey = Services.CommonService.GenerateBillBoardId(billBoard); db.BillBoards.Add(billboardWithGeneratedKey); db.SaveChanges(); return RedirectToAction("Index"); } return View(billBoard); }
public static BillBoard GenerateBillBoardId(BillBoard model) { var type = db.BillBoardTypes.FirstOrDefault(i => i.ID == model.BillBoardTypeId); //var size = db.BillBoardSizes.FirstOrDefault(i => i.ID == model.BillBoardSizeId); int lastId; //var list = db.BillBoards.Where(i => i.BillBoardTypeId == model.BillBoardTypeId && i.ZoneId == model.ZoneId && i.WardId == model.WardId); //ToDo: Need To change here. var list = db.BillBoards.Where(i => i.BillBoardTypeId == model.BillBoardTypeId && i.ZoneWardAreaId == model.ZoneWardAreaId); var shortedList = list.OrderByDescending(i => i.BillBoardLastNo).ToList(); if (shortedList != null && shortedList.Count > 0) { int i = shortedList.First().BillBoardLastNo; i++; model.BillBoardLastNo = i; lastId = i; } else { lastId = 1; model.BillBoardLastNo = 1; } //lastId = list.Max(r => r.BillBoardLastNo) ; //lastId++; var result = String.Format("{0:0000}", lastId); var result2 = lastId.ToString("0000"); var billboardType = db.BillBoardTypes.FirstOrDefault(x => x.ID == model.BillBoardTypeId); var zoneWard = db.ZoneWardAreas.FirstOrDefault(i => i.Id == model.ZoneWardAreaId); //var id = type.ShortCode + "-Z" + model.ZoneId + " W" + model.WardId + " " +size.Height + "F X " + size.Width + "F " + result; //ToDo: Need TO change here--- Size , ward id , zone id var id = type.ShortCode + "-Z" + zoneWard.ZoneNo + " W" + zoneWard.WardNo + " " + billboardType.Length + "F X " + billboardType.Width + "F " + result; model.BillBoardUniqueKey = id; return model; }
public ActionResult Edit(BillBoard billBoard, HttpPostedFileBase photo) { if (ModelState.IsValid) { var billboardWithGeneratedKey = Services.CommonService.GenerateBillBoardId(billBoard); db.Entry(billBoard).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(billBoard); }