// PUT api/PoleTest/5 public IHttpActionResult PutPoleInfo(int id, PoleInfo poleinfo) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != poleinfo.ID) { return BadRequest(); } db.Entry(poleinfo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PoleInfoExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostPoleInfo(PoleInfo poleinfo) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.PoleInfoes.Add(poleinfo); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = poleinfo.ID }, poleinfo); }
public ActionResult Create(PoleInfoViewModel PoleInfo, HttpPostedFileBase file) { string ImageMapPath = ""; string ImagesTakenpath = ""; try { // TODO: Add insert logic here PoleInfo obj = new PoleInfo(); obj.PoleID = PoleInfo.PoleID; obj.TypeID = PoleInfo.TypeID; obj.TaskAddeddate = PoleInfo.TaskAddeddate; obj.TaskPerformeddate = PoleInfo.TaskPerformeddate; obj.AdjacentPoleHeight = PoleInfo.AdjacentPoleHeight; obj.TransFormerLoading = PoleInfo.TransFormerLoading; obj.Notes = PoleInfo.Notes; //obj.UserID = User.Identity.GetUserId(); //PoleInfoEntities objE = new PoleInfoEntities(); var FileSavePathList = objE.FileSavePaths.ToList(); if (Request.Files["ImageMapPathfile"].ContentLength > 0) { var _file = Request.Files["ImageMapPathfile"]; string _savepath = FileSavePathList.SingleOrDefault(p => p.FileFor == "PoleImageMapPath").FilePath; string fileExtension = System.IO.Path.GetExtension(_file.FileName); ImageMapPath = _savepath + PoleInfo.PoleID.ToString().Trim() + "_MapImage" + fileExtension; if (!System.IO.Directory.Exists(_savepath)) { System.IO.Directory.CreateDirectory(_savepath); } _file.SaveAs(ImageMapPath); } if (Request.Files["ImagesTakenpathfile"].ContentLength > 0) { var _file = Request.Files["ImagesTakenpathfile"]; string _savepath = FileSavePathList.SingleOrDefault(p => p.FileFor == "PoleImagesTakenpath").FilePath; string fileExtension = System.IO.Path.GetExtension(_file.FileName); ImagesTakenpath = _savepath + PoleInfo.PoleID.ToString().Trim() + "_TakenImages" + fileExtension; if (!System.IO.Directory.Exists(_savepath)) { System.IO.Directory.CreateDirectory(_savepath); } _file.SaveAs(ImagesTakenpath); } obj.ImageMapPath = ImageMapPath; obj.ImagesTakenpath = ImagesTakenpath; obj.TaskAssainUserID = PoleInfo.TaskAssainUserID; var userbasic = new UserInformationController().GetUserByAspNetUserId(User.Identity.GetUserId()); obj.UserID = userbasic.Id; obj.IsActive = true; obj.CreateDate = DateTime.Now; int Id = Save(obj); return RedirectToAction("Index"); } catch { DeleteFile(ImageMapPath); DeleteFile(ImagesTakenpath); return View(); } }
private int Save(PoleInfo obj) { int ID = 0; string conn = SQLHelper.GetConnectionString(); using (SqlConnection con = new SqlConnection(conn)) { con.Open(); var connection = con; var transaction = connection.BeginTransaction(); Hashtable htbl = new Hashtable(); htbl.Add("@PoleID", obj.PoleID); htbl.Add("@TypeID", obj.TypeID); htbl.Add("@TaskAddeddate", obj.TaskAddeddate); htbl.Add("@TaskPerformeddate", obj.TaskPerformeddate); htbl.Add("@ImageMapPath", obj.ImageMapPath); htbl.Add("@AdjacentPoleHeight", obj.AdjacentPoleHeight); htbl.Add("@TransFormerLoading", obj.TransFormerLoading); htbl.Add("@Notes", obj.Notes); htbl.Add("@ImagesTakenpath", obj.ImagesTakenpath); htbl.Add("@TaskAssainUserID", obj.TaskAssainUserID); htbl.Add("@UserID", obj.UserID); htbl.Add("@IsActive", obj.IsActive); htbl.Add("@TransactionDate", DateTime.Now); try { var dset = SQLHelper.ExecuteProcedureAsFromDataAdapter("SPPoleInfo", htbl, connection, transaction); transaction.Commit(); ID = Convert.ToInt32(dset.Tables[0].Rows[0][0].ToString()); } catch (Exception ex) { string errormsg = ex.Message; transaction.Rollback(); } con.Close(); } return ID; }
public ActionResult Import(PoleInfoViewModel PoleInfo,HttpPostedFileBase file) { try { //return RedirectToAction("Index"); // TODO: Add insert logic here //ViewBag.TaskAssainUser = new SelectList(new UserInformationController().GetDropdownData(), "ID", "UserFullName"); DataSet ds = new DataSet(); if (Request.Files["file"].ContentLength > 0) { string fileExtension =System.IO.Path.GetExtension(Request.Files["file"].FileName); if (fileExtension == ".xls" || fileExtension == ".xlsx") { string fileLocation = Server.MapPath("~/Content/") + Request.Files["file"].FileName; if (System.IO.File.Exists(fileLocation)) { System.IO.File.Delete(fileLocation); } Request.Files["file"].SaveAs(fileLocation); //string _UserID = User.Identity.GetUserId(); userInfo = new UserInformationController().GetUserByAspNetUserId(User.Identity.GetUserId()); DataTable tbl1 = SQLHelper.GetExcelData(fileLocation, "PoleData"); var drs = tbl1.Select("isnull(PoleID,'')=''"); foreach (DataRow row in drs) { tbl1.Rows.Remove(row); } foreach (DataRow dr in tbl1.Rows) { PoleInfo obj = new PoleInfo(); obj.PoleID = dr["PoleID"].ToString(); obj.TypeID = GetPolTypeID(dr["PoleType"].ToString()); DateTime _outdatetime; DateTime? TaskAddeddate = null; if (DateTime.TryParse(dr["TaskAddeddate"].ToString(), out _outdatetime)) { TaskAddeddate = Convert.ToDateTime(dr["TaskAddeddate"].ToString()); } DateTime? TaskPerformeddate = null; if (DateTime.TryParse(dr["TaskPerformeddate"].ToString(), out _outdatetime)) { TaskPerformeddate = Convert.ToDateTime(dr["TaskPerformeddate"].ToString()); } obj.TaskAddeddate = TaskAddeddate; obj.TaskPerformeddate = TaskPerformeddate; obj.ImageMapPath = dr["ImageMapPath"].ToString(); double _outval; double AdjacentPoleHeight = (double.TryParse(dr["AdjacentPoleHeight"].ToString(), out _outval) == false ? default(double) : Convert.ToDouble(dr["AdjacentPoleHeight"].ToString())); obj.AdjacentPoleHeight = AdjacentPoleHeight; obj.TransFormerLoading = dr["TransFormerLoading"].ToString(); obj.Notes = dr["Notes"].ToString(); obj.ImagesTakenpath = dr["ImagesTakenpath"].ToString(); obj.TaskAssainUserID = PoleInfo.TaskAssainUserID; obj.UserID = userInfo.Id; obj.IsActive = true; try { int Id = Save(obj); } catch (Exception ex) { string errormsg = ex.Message; } } } } return RedirectToAction("Index"); } catch(Exception ex) { string dd = ex.Message; return View(ex.Message); } }
public ActionResult Edit(int id, PoleInfoViewModel PoleInfo) { try { // TODO: Add update logic here PoleInfo obj = new PoleInfo(); obj.PoleID = PoleInfo.PoleID; obj.TypeID = PoleInfo.TypeID; obj.TaskAddeddate = PoleInfo.TaskAddeddate; obj.TaskPerformeddate = PoleInfo.TaskPerformeddate; obj.ImageMapPath = PoleInfo.ImageMapPath; obj.AdjacentPoleHeight = PoleInfo.AdjacentPoleHeight; obj.TransFormerLoading = PoleInfo.TransFormerLoading; obj.Notes = PoleInfo.Notes; obj.ImagesTakenpath = PoleInfo.ImagesTakenpath; obj.TaskAssainUserID = PoleInfo.TaskAssainUserID; obj.UpdateDate = DateTime.Now; //obj.UserID = User.Identity.GetUserId(); //PoleInfoEntities objE = new PoleInfoEntities(); var FileSavePathList = objE.FileSavePaths.ToList(); if (Request.Files["ImageMapPathfile"].ContentLength > 0) { var _file = Request.Files["ImageMapPathfile"]; string _savepath = FileSavePathList.SingleOrDefault(p => p.FileFor == "PoleImageMapPath").FilePath; string fileExtension = System.IO.Path.GetExtension(_file.FileName); string ImageMapPath = _savepath + PoleInfo.PoleID.ToString().Trim() + "_MapImage" + fileExtension; _file.SaveAs(ImageMapPath); obj.ImageMapPath = ImageMapPath; } if (Request.Files["ImagesTakenpathfile"].ContentLength > 0) { var _file = Request.Files["ImagesTakenpathfile"]; string _savepath = FileSavePathList.SingleOrDefault(p => p.FileFor == "PoleImagesTakenpath").FilePath; string fileExtension = System.IO.Path.GetExtension(_file.FileName); string ImagesTakenpath = _savepath + PoleInfo.PoleID.ToString().Trim() + "_TakenImages" + fileExtension; _file.SaveAs(ImagesTakenpath); obj.ImagesTakenpath = ImagesTakenpath; } int Id = Save(obj); return RedirectToAction("Index"); } catch { return View(); } }