Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            using (dbDriversLicenseEntities entities = new dbDriversLicenseEntities())
            {
                tblDriversLicenseDetail data = entities.tblDriversLicenseDetails.Where(a => a.PersonId == id).FirstOrDefault();
                if (data != null)
                {
                    entities.tblDriversLicenseDetails.Remove(data);
                    entities.SaveChanges();
                }

                tblPersonDetail tblPersonDetail = entities.tblPersonDetails.Where(a => a.Id == id).FirstOrDefault();
                if (tblPersonDetail != null)
                {
                    entities.tblPersonDetails.Remove(tblPersonDetail);
                    entities.SaveChanges();

                    return(RedirectToAction("ViewLicenseDetails"));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult AddPersonLicenseDetail(PersonLicenseModel model, FormCollection form)
        {
            int id = 0;

            if (ModelState.IsValid)
            {
                dbDriversLicenseEntities entities        = new dbDriversLicenseEntities();
                tblPersonDetail          tblPersonDetail = new tblPersonDetail();
                if (model != null)
                {
                    int count = entities.tblPersonDetails.Where(a => a.PhoneNumber == model.PhoneNumber).Count();
                    if (count > 0)
                    {
                        TempData["Error"] = "Phone Number Already Exist, Try Another!";
                        return(RedirectToAction("Index", "Home"));
                    }
                    int countLic = entities.tblDriversLicenseDetails.Where(a => a.License_number == model.LicenseNumber).Count();
                    if (countLic > 0)
                    {
                        TempData["Error"] = "License Number Already Exist, Try Another!";
                        return(RedirectToAction("Index", "Home"));
                    }

                    tblPersonDetail.Address         = model.Address.Trim();
                    tblPersonDetail.CreatedDate     = DateTime.UtcNow;
                    tblPersonDetail.FirstName       = model.FirstName.Trim();
                    tblPersonDetail.LastName        = model.LastName.Trim();
                    tblPersonDetail.LastUpdatedDate = DateTime.UtcNow;
                    tblPersonDetail.PhoneNumber     = model.PhoneNumber.Trim();
                    entities.tblPersonDetails.Add(tblPersonDetail);
                    entities.SaveChanges();
                    id = tblPersonDetail.Id;
                    if (id > 0)
                    {
                        int Lid = 0;
                        tblDriversLicenseDetail tblDriversLicenseDetail = new tblDriversLicenseDetail();
                        tblDriversLicenseDetail.Issue_date     = Convert.ToDateTime(model.IssueDate);
                        tblDriversLicenseDetail.Expiry_date    = Convert.ToDateTime(model.ExpiryDate);
                        tblDriversLicenseDetail.License_number = model.LicenseNumber.Trim();
                        tblDriversLicenseDetail.PersonId       = id;
                        tblDriversLicenseDetail.LicenseTypeId  = Convert.ToInt32(form["LicenseTypeName"]);
                        entities.tblDriversLicenseDetails.Add(tblDriversLicenseDetail);
                        entities.SaveChanges();
                        Lid = tblDriversLicenseDetail.Id;
                        if (Lid > 0)
                        {
                            return(RedirectToAction("ViewLicenseDetails", "Home"));
                        }
                    }
                }
            }
            else
            {
                GetlicenseTypes();
            }
            return(View("Index", personLicenseModel));
        }
Exemplo n.º 3
0
        public ActionResult Edit(int ID, PersonLicenseModel model, FormCollection form)
        {
            using (dbDriversLicenseEntities entities = new dbDriversLicenseEntities())
            {
                int count = entities.tblPersonDetails.Where(a => a.PhoneNumber == model.PhoneNumber && a.Id != model.PersonId).Count();
                if (count > 0)
                {
                    TempData["Error"] = "Phone Number Already Exist, Try Another!";
                    return(RedirectToAction("Index", "Home"));
                }
                int countLic = entities.tblDriversLicenseDetails.Where(a => a.License_number == model.LicenseNumber && a.PersonId != model.PersonId).Count();
                if (countLic > 0)
                {
                    TempData["Error"] = "License Number Already Exist, Try Another!";
                    return(RedirectToAction("Index", "Home"));
                }


                tblPersonDetail updatedPerson = (from c in entities.tblPersonDetails
                                                 where c.Id == ID
                                                 select c).FirstOrDefault();
                if (updatedPerson != null)
                {
                    updatedPerson.FirstName       = model.FirstName;
                    updatedPerson.LastName        = model.LastName;
                    updatedPerson.Address         = model.Address;
                    updatedPerson.PhoneNumber     = model.PhoneNumber;
                    updatedPerson.LastUpdatedDate = DateTime.UtcNow;
                    entities.SaveChanges();
                    tblDriversLicenseDetail data = (from c in entities.tblDriversLicenseDetails
                                                    where c.PersonId == ID
                                                    select c).FirstOrDefault();

                    if (data != null)
                    {
                        data.License_number = model.LicenseNumber;
                        data.Issue_date     = Convert.ToDateTime(model.IssueDate);
                        data.Expiry_date    = Convert.ToDateTime(model.ExpiryDate);
                        data.LicenseTypeId  = Convert.ToInt32(form["LicenseTypeName"]);
                    }
                    entities.SaveChanges();
                }
            }

            return(RedirectToAction("ViewLicenseDetails"));
        }