public async Task <IActionResult> Edit(int id, [Bind("InsurancePackageID,Name")] InsurancePackage insurancePackage)
        {
            if (id != insurancePackage.InsurancePackageID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(insurancePackage);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InsurancePackageExists(insurancePackage.InsurancePackageID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(insurancePackage));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            InsurancePackage insurancePackage = db.InsurancePackages.Find(id);

            db.InsurancePackages.Remove(insurancePackage);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create([Bind("InsurancePackageID,Name")] InsurancePackage insurancePackage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(insurancePackage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(insurancePackage));
        }
 public ActionResult ChangeStatus(int action, int[] selectedIDs)
 {
     foreach (int IDs in selectedIDs)
     {
         InsurancePackage insurancePackage = db.InsurancePackages.Find(IDs);
         db.InsurancePackages.Attach(insurancePackage);
         insurancePackage.Status = action;
     }
     db.SaveChanges();
     return(Json(selectedIDs, JsonRequestBehavior.AllowGet));
 }
        // GET: Admin/InsurancePackages/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            InsurancePackage insurancePackage = db.InsurancePackages.Find(id);

            if (insurancePackage == null)
            {
                return(HttpNotFound());
            }
            return(View(insurancePackage));
        }
        // GET: Admin/InsurancePackages/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            InsurancePackage insurancePackage = db.InsurancePackages.Find(id);

            if (insurancePackage == null)
            {
                return(HttpNotFound());
            }
            ViewBag.InsuranceId = new SelectList(db.Insurances, "Id", "Name", insurancePackage.InsuranceId);
            return(View(insurancePackage));
        }
 public ActionResult Edit([Bind(Include = "Id,InsuranceId,Name,Description,Price,DurationContract,DurationPay,CreatedAt,UpdatedAt,DeleteAt")] InsurancePackage insurancePackage)
 {
     if (ModelState.IsValid)
     {
         var insurancepackages = new InsurancePackage()
         {
             InsuranceId      = insurancePackage.InsuranceId,
             Id               = insurancePackage.Id,
             Name             = insurancePackage.Name,
             Description      = insurancePackage.Description,
             Price            = insurancePackage.Price,
             DurationContract = insurancePackage.DurationContract,
             DurationPay      = insurancePackage.DurationPay,
             CreatedAt        = DateTime.Now,
             UpdatedAt        = DateTime.Now,
             DeleteAt         = DateTime.Now,
         };
         db.Entry(insurancepackages).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.InsuranceId = new SelectList(db.Insurances, "Id", "Name", insurancePackage.InsuranceId);
     return(View(insurancePackage));
 }
        public ActionResult Create([Bind(Include = "Id,InsuranceId,Name,Description,Price,DurationContract,DurationPay,CreatedAt,UpdatedAt,DeleteAt")] InsurancePackage insurancePackage)
        {
            if (ModelState.IsValid)
            {
                var insurancepackages = new InsurancePackage()
                {
                    InsuranceId      = insurancePackage.InsuranceId,
                    Name             = insurancePackage.Name,
                    Description      = insurancePackage.Description,
                    Price            = insurancePackage.Price,
                    DurationContract = insurancePackage.DurationContract,
                    DurationPay      = insurancePackage.DurationPay,
                    Status           = 1,
                    CreatedAt        = DateTime.Now,
                    UpdatedAt        = DateTime.Now,
                    DeleteAt         = DateTime.Now,
                };
                db.InsurancePackages.Add(insurancepackages);
                db.SaveChanges();
                var Users = db.Users.Include(u => u.Roles).ToList();
                new Thread(() => {
                    foreach (var user in Users)
                    {
                        var senderemail = new MailAddress("*****@*****.**", "test");

                        var receivermail  = new MailAddress(user.Email, "test");
                        var passwordemail = "vtacl123";
                        var subject       = "hehe";
                        string body       = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
                        body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">";
                        body += "</HEAD><BODY><DIV><FONT face=Arial color=#ff0000 size=2>Your account information.";
                        body += "</FONT></DIV></BODY><br/>Name: " + insurancePackage.Name + "<br/>Price:" + insurancePackage.Price + "<br/>Price:" + insurancePackage.Description + "</HTML>";

                        var smtp = new SmtpClient
                        {
                            Host                  = "smtp.gmail.com",
                            Port                  = 587,
                            DeliveryMethod        = SmtpDeliveryMethod.Network,
                            EnableSsl             = true,
                            UseDefaultCredentials = false,
                            Credentials           = new NetworkCredential(senderemail.Address, passwordemail)
                        };
                        using (var mess = new MailMessage(senderemail, receivermail)
                        {
                            IsBodyHtml = true,
                            Subject = subject,
                            Body = body
                        }
                               )
                        {
                            smtp.Send(mess);
                        };
                    }
                }).Start();


                return(RedirectToAction("Index"));
            }

            ViewBag.InsuranceId = new SelectList(db.Insurances, "Id", "Name", insurancePackage.InsuranceId);
            return(View(insurancePackage));
        }