public ActionResult DeleteComplaint(int id) { try { tbl_ComplaintMaster abc = _complaint.Get(id); _complaint.Remove(id, true); return(Json("success", JsonRequestBehavior.AllowGet)); } catch { return(Json("failed", JsonRequestBehavior.AllowGet)); } }
public ActionResult Addcomplaint(string id) { ViewBag.comList = new SelectList(_catComplaint.GetAll(), "pkid", "CategoryName"); ViewBag.cityList = new SelectList(_city.GetAll().Where(x => x.StateID == 1646).ToList(), "ID", "Name"); if (!String.IsNullOrWhiteSpace(id)) { int _id = Convert.ToInt32(id); tbl_ComplaintMaster model = _complaint.Get(_id); tbl_ComplaintMasterss abc = new tbl_ComplaintMasterss(); abc.pkid = model.pkid; abc.Category_fkid = model.Category_fkid; abc.ComplaintDescription = model.ComplaintDescription; abc.ComplaintName = model.ComplaintName; abc.AddedDate = model.AddedDate; abc.Active = model.Active; abc.Longitutde = model.Longitutde; abc.Latitude = model.Latitude; abc.City_fkid = model.City_fkid; abc.ImagePath = model.ImagePath; return(View(abc)); } return(View()); }
public async Task <IHttpActionResult> MediaUpload() { WMC_WebApplicationEntities db = new WMC_WebApplicationEntities(); // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var provider = await Request.Content.ReadAsMultipartAsync <InMemoryMultipartFormDataStreamProvider>(new InMemoryMultipartFormDataStreamProvider()); //access form data NameValueCollection model = provider.FormData; //access files IList <HttpContent> files = provider.Files; returnAPiFlag abcd = new returnAPiFlag(); tbl_ComplaintMaster abc = new tbl_ComplaintMaster(); try { abc.pkid = Convert.ToInt32(model["pkid"]); abc.Category_fkid = Convert.ToInt32(model["Category_fkid"]); abc.ComplaintDescription = model["ComplaintDescription"]; abc.ComplaintName = model["ComplaintName"]; abc.AddedDate = DateTime.Now; abc.Active = Convert.ToInt32(model["Active"]); abc.Longitutde = model["Longitutde"]; abc.Latitude = model["Latitude"]; abc.City_fkid = Convert.ToInt32(model["City_fkid"]); abc.ImagePath = model["ImagePath"]; abc.ShowIdentity = model["ShowIdentity"]; } catch { abcd.status = "Entered Required Field"; abcd.flag = true; return(Json(abcd)); } try { string id; id = User.Identity.GetUserId(); id = RequestContext.Principal.Identity.GetUserId(); if (abc.pkid == 0) { var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { var docfiles = new List <string>(); for (int i = 0; i <= httpRequest.Files.Count - 1; i++) { WebFunction web = new WebFunction(); var postedFile = httpRequest.Files[i]; DateTime date = DateTime.Now; string dates = date.Day.ToString() + date.Month.ToString() + date.Year.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.ToString("tt"); var returnpath = "/UploadFiles/Complaints/" + dates + postedFile.FileName; var filePath = Path.Combine(HttpContext.Current.Server.MapPath("/UploadFiles/Complaints/"), dates + postedFile.FileName); postedFile.SaveAs(filePath); abc.ImagePath = returnpath; } } abc.LastModifiedDate = DateTime.Now; abc.User_fkid = id; db.tbl_ComplaintMaster.Add(abc); db.SaveChanges(); abcd.status = "Data Save Successfully"; abcd.flag = true; } else { var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { var docfiles = new List <string>(); for (int i = 0; i <= httpRequest.Files.Count - 1; i++) { WebFunction web = new WebFunction(); var postedFile = httpRequest.Files[i]; DateTime date = DateTime.Now; string dates = date.Day.ToString() + date.Month.ToString() + date.Year.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + date.ToString("tt"); var returnpath = "/UploadFiles/Complaints/" + dates + postedFile.FileName; var filePath = Path.Combine(HttpContext.Current.Server.MapPath("/UploadFiles/Complaints/"), dates + postedFile.FileName); postedFile.SaveAs(filePath); abc.ImagePath = returnpath; } } abc.LastModifiedDate = DateTime.Now; db.tbl_ComplaintMaster.Attach(abc); db.Entry(model).State = EntityState.Modified; db.SaveChanges(); abcd.status = "Data updated Successfully"; abcd.flag = true; } return(Json(abcd)); } catch (Exception e) { abcd.status = "Data Save Failed"; abcd.flag = false; return(Json(abc)); } }
public ActionResult Addcomplaint(tbl_ComplaintMasterss model, HttpPostedFileBase image) { ViewBag.comList = new SelectList(_catComplaint.GetAll(), "pkid", "CategoryName"); ViewBag.cityList = new SelectList(_city.GetAll().Where(x => x.StateID == 1646).ToList(), "ID", "Name"); try { if (model.pkid == 0) { tbl_ComplaintMaster abc = new tbl_ComplaintMaster(); if (image != null) { WebFunction web = new WebFunction(); model.ImagePath = web.Storefile(image, 1); } abc.Category_fkid = model.Category_fkid; abc.ComplaintDescription = model.ComplaintDescription; abc.ComplaintName = model.ComplaintName; abc.AddedDate = model.AddedDate; abc.Active = model.Active; abc.Longitutde = model.Longitutde; abc.Latitude = model.Latitude; abc.City_fkid = model.City_fkid; abc.ImagePath = model.ImagePath; abc.LastModifiedDate = DateTime.Now; _complaint.Add(abc); } else { int _id = Convert.ToInt32(model.pkid); tbl_ComplaintMaster abc = _complaint.Get(_id); if (image != null) { string path = System.Web.HttpContext.Current.Server.MapPath(model.ImagePath); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } WebFunction web = new WebFunction(); model.ImagePath = web.Storefile(image, 1); } abc.pkid = model.pkid; abc.Category_fkid = model.Category_fkid; abc.ComplaintDescription = model.ComplaintDescription; abc.ComplaintName = model.ComplaintName; abc.AddedDate = model.AddedDate; abc.Active = model.Active; abc.Longitutde = model.Longitutde; abc.Latitude = model.Latitude; abc.City_fkid = model.City_fkid; abc.ImagePath = model.ImagePath; abc.LastModifiedDate = DateTime.Now; _complaint.Update(abc); } return(RedirectToAction("Addcomplaint", "Administration")); } catch (Exception e) { Commonfunction.LogError(e, Server.MapPath("~/Log.txt")); ViewBag.Exception = e.Message; return(View()); } }