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;
            }
        }
Ejemplo n.º 3
0
        public void ArchiveServiceRep(string id)
        {
            var ArchiveRep = new ServiceRepresentativeRepository();
            var ar         = new ArchiveServiceRepresentativeRepository();

            ServiceRepresentative e = ArchiveRep.GetByServRepNo(id);
            var user = con.Users.Find(e.IDNumber);

            if (e != null || user != null)
            {
                var arch = new ArchiveServiceRepresentative()
                {
                    ServiceRepIdNo = e.ServiceRepIdNo,
                    IDNumber       = e.IDNumber,
                    Fullname       = e.Fullname,
                    Email          = e.Email,
                    ContactNo      = e.ContactNo
                };

                con.Users.Remove(user);

                ar.Insert(arch);
                ArchiveRep.Delete(e);
            }
        }
 public List <ServiceRepresentativeView> GetAll()
 {
     using (var servicerreprepo = new ServiceRepresentativeRepository())
     {
         return(servicerreprepo.GetAll().Select(x => new ServiceRepresentativeView()
         {
             ServiceRepIdNo = x.ServiceRepIdNo, IDNumber = x.IDNumber, Fullname = x.Fullname, Email = x.Email, ContactNo = x.ContactNo
         }).ToList());
     }
 }
 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);
     }
 }
Ejemplo n.º 6
0
        public void Restore(string id)
        {
            var ArchiveRep = new ServiceRepresentativeRepository();
            var ar         = new ArchiveServiceRepresentativeRepository();

            ArchiveServiceRepresentative arch = ar.GetById(id);

            if (arch != null)
            {
                var mm = new ServiceRepresentative()
                {
                    ServiceRepIdNo = arch.ServiceRepIdNo,
                    IDNumber       = arch.IDNumber,
                    Fullname       = arch.Fullname,
                    Email          = arch.Email,
                    ContactNo      = arch.ContactNo
                };

                var newuser = new ApplicationUser()
                {
                    Id           = mm.IDNumber,
                    UserName     = mm.IDNumber,
                    FullName     = mm.Fullname,
                    Email        = mm.Email,
                    PasswordHash = UserManager.PasswordHasher.HashPassword(genePassword(mm.IDNumber))
                };

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

                ar.Delete(arch);
                ArchiveRep.Insert(mm);

                rb.AddUserToRole(newuser.Id, "Service Representative");
            }
        }