public void AddServiceRep(ServiceRepresentativeView objServRepView)
        {
            using (var servreprepo = new ServiceRepresentativeRepository())
            {
                var newuser = new ApplicationUser()
                {
                    Id           = objServRepView.IDNumber,
                    UserName     = objServRepView.IDNumber,
                    FullName     = objServRepView.Fullname,
                    Email        = objServRepView.Email,
                    PasswordHash = UserManager.PasswordHasher.HashPassword(genePassword(objServRepView.IDNumber))
                };

                var result = UserManager.CreateAsync(newuser, genePassword(objServRepView.IDNumber));

                var servrep = new ServiceRepresentative
                {
                    ServiceRepIdNo = geneServRepNo(objServRepView.IDNumber, objServRepView.Fullname),
                    IDNumber       = objServRepView.IDNumber,
                    Fullname       = objServRepView.Fullname,
                    Email          = objServRepView.Email,
                    ContactNo      = objServRepView.ContactNo,
                    AppUserId      = newuser.Id
                };

                servreprepo.Insert(servrep);

                rb.AddUserToRole(objServRepView.IDNumber, "Service Representative");
            }
        }
        public void UpdateServiceRep(ServiceRepresentativeView model)
        {
            using (var servreprepo = new ServiceRepresentativeRepository())
            {
                ServiceRepresentative sr = servreprepo.GetByServRepNo(model.ServiceRepIdNo);

                if (sr != null)
                {
                    sr.IDNumber  = model.IDNumber;
                    sr.Fullname  = model.Fullname;
                    sr.Email     = model.Email;
                    sr.ContactNo = model.ContactNo;

                    servreprepo.Update(sr);
                }
            }

            ApplicationUser user = UserManager.FindById(model.IDNumber);

            if (user != null)
            {
                user.Email    = model.Email;
                user.FullName = model.Fullname;
            }
        }
 public ActionResult Edit(ServiceRepresentativeView model)
 {
     if (ModelState.IsValid)
     {
         servrep.UpdateServiceRep(model);
         return(RedirectToAction("GetAll"));
     }
     return(View(model));
 }
 public ServiceRepresentativeView GetbyServRepNo(string repno)
 {
     using (var sreprepo = new ServiceRepresentativeRepository())
     {
         ServiceRepresentative sr = sreprepo.GetByServRepNo(repno);
         var srep = new ServiceRepresentativeView();
         if (sr != null)
         {
             srep.ServiceRepIdNo = sr.ServiceRepIdNo;
             srep.IDNumber       = sr.IDNumber;
             srep.Fullname       = sr.Fullname;
             srep.Email          = sr.Email;
             srep.ContactNo      = sr.ContactNo;
         }
         return(srep);
     }
 }
 public ActionResult AddServiceRep(ServiceRepresentativeView model)
 {
     if (ModelState.IsValid)
     {
         foreach (ServiceRepresentativeView v in servrep.GetAll())
         {
             if (model.IDNumber == v.IDNumber)
             {
                 ViewBag.Result = "Service representative with this ID Number already exist.";
                 return(View(model));
             }
         }
         servrep.AddServiceRep(model);
         return(RedirectToAction("GetAll"));
     }
     return(View(model));
 }