// GET: Expense/Delete/5
        public ActionResult Delete(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            expenses dep = expService.GetById(id);
            exp      p   = new exp()
            {
                DateExpense   = dep.DateExpense,
                NatureDepense = (NatureVM)dep.NatureDepense,
                nbNuitete     = dep.nbNuitete,
                moyTransport  = (MoyeneVM)dep.moyTransport,
                distance      = dep.distance,
                Justificatif  = dep.Justificatif,
                MontantTotal  = dep.MontantTotal,
                commentaire   = dep.commentaire,
                mm_id_mission = dep.mm_id_mission
            };

            if (dep == null)
            {
                return(HttpNotFound());
            }
            expService.Delete(dep);
            expService.Commit();
            return(View(p));
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            expenses expenses = db.expenses.Find(id);

            db.expenses.Remove(expenses);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
 public ActionResult Edit([Bind(Include = "exp_id,exps_id,emp_name,exps_date,exp_payee_name,exp_type,exp_amt,exp_remarks")] expenses expenses)
 {
     if (ModelState.IsValid)
     {
         db.Entry(expenses).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.exps_id = new SelectList(db.expense_Types, "exps_id", "exps_type", expenses.exps_id);
     return(View(expenses));
 }
Exemple #4
0
        // GET: expenses/Details/8
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            expenses expenses = db.expenses.Find(id);

            if (expenses == null)
            {
                return(HttpNotFound());
            }
            return(View(expenses));
        }
Exemple #5
0
        // GET: expenses/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            expenses expenses = db.expenses.Find(id);

            if (expenses == null)
            {
                return(HttpNotFound());
            }
            ViewBag.exps_id = new SelectList(db.expense_Types, "exps_id", "exps_type", expenses.exps_id);
            return(View(expenses));
        }
        /// <summary>
        /// Save expense update or/and create, set createdAt date, check good set relationships id for expense_type
        /// If it encounters a sudden error, it will notify the user about it, e.g.sudden deletion of the table
        /// </summary>
        private void SaveExpensesCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            var changesEntities = from ce in context.ChangeTracker.Entries()
                                  where ce.State != EntityState.Unchanged
                                  select ce;

            foreach (var change in changesEntities)
            {
                if (change.Entity is expenses)
                {
                    expenses expense = (expenses)change.Entity;

                    if (change.State == EntityState.Added)
                    {
                        expense.created_at = DateTime.Now;
                    }

                    var type = (from o in context.expenses_type
                                where o.id == expense.expenses_type_id
                                select o).FirstOrDefault();

                    if (type == null)
                    {
                        MessageBox.Show("Give invalid relationship id for expense id: " + expense.id);
                        return;
                    }
                }
            }

            try
            {
                expensesTypeSource.View.Refresh();
                expensesTypeSource.View.MoveCurrentToFirst();

                expensesSource.View.Refresh();
                expensesSource.View.MoveCurrentToFirst();

                context.SaveChanges();
            } catch (Exception)
            {
                MessageBox.Show("Something went wrong");
            }
        }
 public ActionResult Delete(int id, exp evt)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (id == null)
             {
                 return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
             }
             expenses dep = expService.GetById(id);
             evt = new exp()
             {
                 DateExpense   = dep.DateExpense,
                 NatureDepense = (NatureVM)dep.NatureDepense,
                 nbNuitete     = dep.nbNuitete,
                 moyTransport  = (MoyeneVM)dep.moyTransport,
                 distance      = dep.distance,
                 Justificatif  = dep.Justificatif,
                 MontantTotal  = dep.MontantTotal,
                 commentaire   = dep.commentaire,
                 mm_id_mission = dep.mm_id_mission
             };
             if (dep == null)
             {
                 return(HttpNotFound());
             }
             Console.WriteLine("Deleted");
             expService.Delete(dep);
             expService.Commit();
             // Service.Dispose();
             return(RedirectToAction("Index"));
         }
         // TODO: Add delete logic here
         return(View(evt));
     }
     catch
     {
         return(View());
     }
 }
        /// <summary>
        /// Delete expense for clicked object
        /// If it encounters a sudden error, it will notify the user about it, e.g.sudden deletion of the table
        /// </summary>
        private void DeleteExpenseCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            expenses obj = e.Parameter as expenses;

            if (obj == null)
            {
                return;
            }

            try
            {
                context.expenses.Remove(obj);

                expensesSource.View.Refresh();
                expensesSource.View.MoveCurrentToFirst();

                context.SaveChanges();
            } catch (Exception)
            {
                MessageBox.Show("Something went wrong");
            }
        }
        public ActionResult Create(expenses d, HttpPostedFileBase file, int abc)
        {
            var missions = pp.GetMany().ToList();

            ViewBag.listmiss = new SelectList(missions, "libelle", "libelle");
            ViewBag.listmiss = missions;
            if (!ModelState.IsValid || file == null || file.ContentLength == 0)
            {
                RedirectToAction("Create");
            }
            var fileName = "";

            if (file.ContentLength > 0)
            {
                fileName = Path.GetFileName(file.FileName);
                var path = Path.Combine(Server.MapPath("/Content/Upload/"), file.FileName);
                file.SaveAs(path);
            }
            //var MissionId = expenses.Equals.
            //expenses d = new expenses()
            //{
            //    DateExpense = dep.DateExpense,
            //    NatureDepense = (Nature)dep.NatureDepense,
            //    nbNuitete = dep.nbNuitete,
            //    moyTransport = (Moyene)dep.moyTransport,
            //    distance = dep.distance,
            //    Justificatif = file.FileName,
            //    MontantTotal = dep.MontantTotal,
            //    commentaire = dep.commentaire,
            //    mm_id_mission = dep.mm_id_mission

            //};


            d.mm_id_mission = abc;
            expService.Add(d);
            expService.Commit();
            // expService.Dispose();   //  @Html.DropDownList("m_id_mission", (SelectList)ViewData["listmiss



            string subject = "sssssssssssssssssssss";

            string body = "bbbbbbbbbbbbbbbbbbbbbbbbb" +
                          "<br/><a href = '></a>";

            var smtp = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = true,
                Credentials           = new NetworkCredential("*****@*****.**", "esprit2018"),
                Timeout               = 20000
            };
            MailMessage p = new MailMessage("*****@*****.**", "*****@*****.**");

            p.Subject    = subject;
            p.Body       = body;
            p.IsBodyHtml = true;


            smtp.Send(p);


            return(RedirectToAction("Index"));
        }