public ActionResult deleteDoc(int id, int DID, int menuid) { try { //int Empid = Convert.ToInt32(Url.RequestContext.RouteData.Values["id"].ToString()); TradeLicenseService objTradeService = new TradeLicenseService(); TradeDocumentItem objDoc = new TradeDocumentItem(); objDoc = objTradeService.getByID(DID); string path = objDoc.FileUrl; var fullPath = Server.MapPath(path); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } db.TradeDocuments.Remove(db.TradeDocuments.Find(DID)); db.SaveChanges(); //ViewBag.Empid = Empid; ViewBag.Menuid = Request.QueryString["menuId"]; } catch (Exception ex) { return(View("Error")); } return(RedirectToAction("Edit", new { @id = id, @menuId = Request.QueryString["menuId"] })); }
public TradeDocumentItem getByID(int id) { Mapper.CreateMap <TradeDocument, TradeDocumentItem>(); TradeDocument objDoc = Dbcontext.TradeDocuments.SingleOrDefault(m => m.TradeDOcId == id); TradeDocumentItem objDocItem = Mapper.Map <TradeDocumentItem>(objDoc); Dbcontext.TradeDocuments.Remove(objDoc); return(objDocItem); }