public ActionResult Delete(int Code) { AVANCES Selected = BD.AVANCES.Find(Code); BD.AVANCES.Remove(Selected); BD.SaveChanges(); return(RedirectToAction("Index")); }
private void InsertIntoList(Stream fStream, DataTable listTable) { try { for (int iRow = 0; iRow < listTable.Rows.Count; iRow++) { string MATRICULE = listTable.Rows[iRow][0] != null?Convert.ToString(listTable.Rows[iRow][0]) : ""; string FULLENAME = listTable.Rows[iRow][1] != null?Convert.ToString(listTable.Rows[iRow][1]) : ""; string MONTANT = listTable.Rows[iRow][2] != null?Convert.ToString(listTable.Rows[iRow][2]) : "0"; string DATE = listTable.Rows[iRow][3] != null?Convert.ToString(listTable.Rows[iRow][3]) : DateTime.Today.ToShortDateString(); string TYPE = listTable.Rows[iRow][4] != null?Convert.ToString(listTable.Rows[iRow][4]) : ""; EMPLOYEES SelectedEmploye = BD.EMPLOYEES.Where(Element => Element.NUMERO == MATRICULE).FirstOrDefault(); if (SelectedEmploye == null) { SelectedEmploye = new EMPLOYEES(); SelectedEmploye.FULLNAME = FULLENAME; SelectedEmploye.NUMERO = MATRICULE; if (BD.DECLARATIONS.FirstOrDefault() != null) { SelectedEmploye.SOCIETES = BD.DECLARATIONS.FirstOrDefault(); SelectedEmploye.SOCIETE = BD.DECLARATIONS.FirstOrDefault().ID; } BD.EMPLOYEES.Add(SelectedEmploye); BD.SaveChanges(); } DateTime dateValue; if (DateTime.TryParse(DATE, out dateValue)) { DateTime NewDate = DateTime.Parse(DATE); AVANCES nouvelleAvance = new AVANCES(); nouvelleAvance.EMPLOYEE = SelectedEmploye.ID; nouvelleAvance.EMPLOYEES = SelectedEmploye; nouvelleAvance.MONTANT = !string.IsNullOrEmpty(MONTANT) ? decimal.Parse(MONTANT) : 0; nouvelleAvance.DATE = NewDate; nouvelleAvance.MOIS = NewDate.Month; nouvelleAvance.ANNEE = NewDate.Year; nouvelleAvance.TYPE = TYPE; BD.AVANCES.Add(nouvelleAvance); BD.SaveChanges(); } } } catch (Exception) { } finally { }; }
public ActionResult SendForm(string Mode, string Code) { string MATRICULE = Request.Params["MATRICULE"] != null ? Request.Params["MATRICULE"].ToString() : string.Empty; string employee = Request.Params["employee"] != null ? Request.Params["employee"].ToString() : string.Empty; string MONTANT = Request.Params["MONTANT"] != null ? Request.Params["MONTANT"].ToString() : "0"; string DATE = Request.Params["DATE"] != null ? Request.Params["DATE"].ToString() : string.Empty; string TYPE = Request.Params["TYPE"] != null ? Request.Params["TYPE"].ToString() : string.Empty; DateTime SelectedDate = DateTime.Parse(DATE); int ID = int.Parse(employee); EMPLOYEES SelectedEmployee = BD.EMPLOYEES.Find(ID); if (Mode == "Create") { AVANCES NouvelleAvance = new AVANCES(); NouvelleAvance.DATE = SelectedDate; NouvelleAvance.ANNEE = SelectedDate.Year; NouvelleAvance.MOIS = SelectedDate.Month; NouvelleAvance.MONTANT = decimal.Parse(MONTANT); NouvelleAvance.EMPLOYEES = SelectedEmployee; NouvelleAvance.EMPLOYEE = ID; NouvelleAvance.TYPE = TYPE; BD.AVANCES.Add(NouvelleAvance); BD.SaveChanges(); } if (Mode == "Edit") { int SeletedAvanceID = int.Parse(Code); AVANCES SelectedAvance = BD.AVANCES.Find(SeletedAvanceID); SelectedAvance.DATE = SelectedDate; SelectedAvance.ANNEE = SelectedDate.Year; SelectedAvance.MOIS = SelectedDate.Month; SelectedAvance.MONTANT = decimal.Parse(MONTANT); SelectedAvance.EMPLOYEES = SelectedEmployee; SelectedAvance.EMPLOYEE = ID; SelectedAvance.TYPE = TYPE; BD.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Form(string Mode, int Code) { AVANCES Element = new AVANCES(); if (Mode == "Create") { ViewBag.FULLNAME = string.Empty; ViewBag.MATRICULE = string.Empty; ViewBag.TITRE = "NOUVELLE DEMANDE"; Element.DATE = DateTime.Today; } if (Mode == "Edit") { Element = BD.AVANCES.Find(Code); ViewBag.FULLNAME = Element.EMPLOYEES.FULLNAME; ViewBag.MATRICULE = Element.EMPLOYEES.NUMERO; ViewBag.TITRE = "MODIFIER UNE DEMANDE"; } ViewBag.Mode = Mode; ViewBag.Code = Code; return(View(Element)); }