public async Task <IActionResult> Edit(int id, [Bind("Id,Title,IconName,Content")] OurService ourService) { ViewBag.NavigatedTO = "Services"; if (id != ourService.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ourService); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OurServiceExists(ourService.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ourService)); }
public OurService GetServiceById(long Id) { using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.GetServicesById, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@Id", Id)); try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); OurService service = new OurService(); service = UtilityManager.DataReaderMap <OurService>(reader); return(service); } catch (Exception e) { throw new Exception("Exception retrieving reviews. " + e.Message); } finally { connection.Close(); } } }
public bool UpdateService(OurService services) { bool isUpdate = true; using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.UpdateServices, connection); command.CommandType = CommandType.StoredProcedure; foreach (var service in services.GetType().GetProperties()) { string name = service.Name; var value = service.GetValue(services, null); command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value)); } try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception e) { isUpdate = false; throw new Exception("Exception Updating Data." + e.Message); } finally { connection.Close(); } } return(isUpdate); }
public ActionResult DeleteConfirmed(int id) { OurService ourService = db.OurService.Find(id); db.OurService.Remove(ourService); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Id,Title,IconName,Content")] OurService ourService) { ViewBag.NavigatedTO = "Services"; if (ModelState.IsValid) { _context.Add(ourService); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(ourService)); }
public async Task <IActionResult> OnPostAsync(OurService OurService) { if (!ModelState.IsValid) { return(Page()); } _db.OurService.Add(OurService); await _db.SaveChangesAsync(); return(RedirectToPage("Index")); }
// GET: Admin/OurServices/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OurService ourService = db.OurService.Find(id); if (ourService == null) { return(HttpNotFound()); } return(View(ourService)); }
// GET: Admin/OurServices/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OurService ourService = db.OurService.Find(id); if (ourService == null) { return(HttpNotFound()); } ViewBag.LanguageCode = new SelectList(db.languageType, "Lanid", "Type", ourService.languageType); return(View(ourService)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } OurService = await _db.OurService.FirstOrDefaultAsync(m => m.Id == id); if (OurService == null) { return(NotFound()); } return(Page()); }
public ActionResult Create([Bind(Include = "id,image,Title,Subtitle,Url,Lanid")] OurService ourService, HttpPostedFileBase Image) { if (ModelState.IsValid) { if (Image != null) { ourService.image = Guid.NewGuid() + Path.GetExtension(Image.FileName); Image.SaveAs(Server.MapPath("/PageImages/" + ourService.image)); } db.OurService.Add(ourService); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LanguageCode = new SelectList(db.languageType, "Lanid", "Type", ourService.languageType); return(View(ourService)); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } OurService = await _context.OurService.FindAsync(id); if (OurService != null) { _context.OurService.Remove(OurService); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public ActionResult Edit([Bind(Include = "id,image,Title,Subtitle,Url,Lanid")] OurService ourService, HttpPostedFileBase imgUp) { if (ModelState.IsValid) { if (imgUp != null) { if (ourService.image != null) { System.IO.File.Delete(Server.MapPath("/PageImages/" + ourService.image)); } ourService.image = Guid.NewGuid() + Path.GetExtension(imgUp.FileName); imgUp.SaveAs(Server.MapPath("/PageImages/" + ourService.image)); } db.Entry(ourService).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.LanguageCode = new SelectList(db.languageType, "Lanid", "Type", ourService.languageType); return(View(ourService)); }
public long InsertService(OurService service) { long id = 0; using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.InsertServices, connection); command.CommandType = CommandType.StoredProcedure; SqlParameter returnValue = new SqlParameter("@" + "Id", SqlDbType.Int); returnValue.Direction = ParameterDirection.Output; command.Parameters.Add(returnValue); foreach (var services in service.GetType().GetProperties()) { if (services.Name != "Id") { string name = services.Name; var value = services.GetValue(service, null); command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value)); } } try { connection.Open(); command.ExecuteNonQuery(); id = (int)command.Parameters["@Id"].Value; } catch (Exception ex) { throw new Exception("Execption Adding Data. " + ex.Message); } finally { connection.Close(); } } return(id); }
public static long InsertService(OurService service) { SqlServiceProvider provider = new SqlServiceProvider(); return(provider.InsertService(service)); }
public static bool UpdateService(OurService service) { SqlServiceProvider provider = new SqlServiceProvider(); return(provider.UpdateService(service)); }