public void DeleteRecord(string index) { try { //Step 1 Code to delete the object from the database PostRequest <EmployeePenalty> req = new PostRequest <EmployeePenalty>(); EmployeePenalty p = new EmployeePenalty(); p.recordId = index; req.entity = p; PostResponse <EmployeePenalty> resp = _employeeService.ChildDelete <EmployeePenalty>(req); if (!resp.Success) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(resp); return; } //Step 2 : remove the object from the store Store1.Remove(index); //Step 3 : Showing a notification for the user Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordDeletedSucc }); } catch (Exception ex) { //In case of error, showing a message box to the user X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorDeletingRecord).Show(); } }
public ActionResult DeleteConfirmed(int id) { EmployeePenalty employeePenalty = db.EmployeePenalties.Find(id); db.EmployeePenalties.Remove(employeePenalty); db.SaveChanges(); return(RedirectToAction("EmployeePenaltyIndex")); }
public ActionResult Edit([Bind(Include = "Id,EmployeeId,PenaltyId,Month,Status,TimeStamp")] EmployeePenalty employeePenalty) { if (ModelState.IsValid) { db.Entry(employeePenalty).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("EmployeePenaltyIndex")); } ViewBag.EmployeeId = new SelectList(db.AspNetEmployees.Where(x => x.AspNetUser.Status != "False"), "Id", "Name", employeePenalty.EmployeeId); ViewBag.PenaltyId = new SelectList(db.EmployeePenaltyTypes, "Id", "PenaltyType", employeePenalty.PenaltyId); return(View(employeePenalty)); }
// GET: EmployeePenalties/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EmployeePenalty employeePenalty = db.EmployeePenalties.Find(id); if (employeePenalty == null) { return(HttpNotFound()); } return(View(employeePenalty)); }
// GET: EmployeePenalties/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EmployeePenalty employeePenalty = db.EmployeePenalties.Find(id); if (employeePenalty == null) { return(HttpNotFound()); } ViewBag.EmployeeId = new SelectList(db.AspNetEmployees.Where(x => x.AspNetUser.Status != "False"), "Id", "Name", employeePenalty.EmployeeId); ViewBag.PenaltyId = new SelectList(db.EmployeePenaltyTypes, "Id", "PenaltyType", employeePenalty.PenaltyId); return(View(employeePenalty)); }
public ActionResult Create([Bind(Include = "Id,EmployeeId,PenaltyId,Month,Status,TimeStamp")] EmployeePenalty employeePenalty) { if (ModelState.IsValid) { var datetime = DateTime.Now; employeePenalty.TimeStamp = datetime; var month = Request.Form["Month"]; employeePenalty.Month = month; employeePenalty.Status = "Created"; db.EmployeePenalties.Add(employeePenalty); db.SaveChanges(); return(RedirectToAction("EmployeePenaltyIndex")); } ViewBag.EmployeeId = new SelectList(db.AspNetEmployees.Where(x => x.AspNetUser.Status != "False"), "Id", "Name", employeePenalty.EmployeeId); ViewBag.PenaltyId = new SelectList(db.EmployeePenaltyTypes, "Id", "PenaltyType", employeePenalty.PenaltyId); return(View(employeePenalty)); }
protected void SaveNewRecord(object sender, DirectEventArgs e) { //Getting the id to check if it is an Add or an edit as they are managed within the same form. string id = e.ExtraParams["id"]; string obj = e.ExtraParams["values"]; EmployeePenalty b = JsonConvert.DeserializeObject <EmployeePenalty>(obj); //if (referToPositionId.SelectedItem != null) // b.referToPositionName = referToPositionId.SelectedItem.Text; //if (tsId.SelectedItem != null) // b.tsName = tsId.SelectedItem.Text; b.recordId = CurrentpenaltyId.Text; // Define the object to add or edit as null b.apStatus = string.IsNullOrEmpty(b.apStatus) ? "1" : b.apStatus; if (string.IsNullOrEmpty(CurrentpenaltyId.Text)) { try { //New Mode //Step 1 : Fill The object and insert in the store PostRequest <EmployeePenalty> request = new PostRequest <EmployeePenalty>(); request.entity = b; PostResponse <EmployeePenalty> r = _employeeService.ChildAddOrUpdate <EmployeePenalty>(request); //check if the insert failed if (!r.Success)//it maybe be another condition { //Show an error saving... X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r);; return; } else { b.recordId = r.recordId; //Add this record to the store Store1.Reload(); CurrentpenaltyId.Text = b.recordId; //Display successful notification Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordSavingSucc }); RowSelectionModel sm = this.GridPanel1.GetSelectionModel() as RowSelectionModel; sm.DeselectAll(); sm.Select(b.recordId.ToString()); } } catch (Exception ex) { //Error exception displaying a messsage box X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorSavingRecord).Show(); } } else { //Update Mode try { //getting the id of the record PostRequest <EmployeePenalty> request = new PostRequest <EmployeePenalty>(); request.entity = b; b.recordId = CurrentpenaltyId.Text; PostResponse <EmployeePenalty> r = _employeeService.ChildAddOrUpdate <EmployeePenalty>(request); //Step 1 Selecting the object or building up the object for update purpose //Step 2 : saving to store //Step 3 : Check if request fails if (!r.Success)//it maybe another check { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r); return; } else { Store1.Reload(); Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordUpdatedSucc }); this.EditRecordWindow.Close(); } } catch (Exception ex) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show(); } } }