示例#1
0
        public async Task <IHttpActionResult> delete(string userId)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            Boolean result = true;

            DAL.User       nowUser    = _db.Users.Where(p => p.userID == userId).First();
            DAL.AspNetUser nowAccount = _db.AspNetUsers.Where(p => p.Id == userId).First();
            if (nowUser != null && nowAccount != null)
            {
                try
                {
                    System.Web.HttpContext.Current.Application.Lock();
                    _db.Users.Remove(nowUser);
                    _db.SaveChanges();

                    _db.AspNetUsers.Remove(nowAccount);
                    _db.SaveChanges();
                    System.Web.HttpContext.Current.Application.UnLock();
                }
                catch (Exception e)
                {
                    result = false;
                }
            }

            return(Json(new { result = result }));
        }
        public void DodajNovogVozaca(KorisnikBDO korisnikBDO)
        {
            var korisnikDB = new DAL.AspNetUser();

            korisnikDB.Ime        = korisnikBDO.Ime;
            korisnikDB.Prezime    = korisnikBDO.Prezime;
            korisnikDB.Telefon    = korisnikBDO.Telefon;
            korisnikDB.Spol       = korisnikBDO.Spol;
            korisnikDB.KorisnikID = db.AspNetUsers.Count() + 1;
            korisnikDB.UserName   = korisnikBDO.UserName;
            korisnikDB.Id         = korisnikBDO.UserName;
            // korisnikDB.PasswordHash=Has
            //   korisnikDB.GradID = korisnikBDO.GradID;
            //   korisnikDB.DatumRodjenja = korisnikBDO.DatumRodjenja;
            //   korisnikDB.ProfilnaSlika = korisnikBDO.ProfilnaSlika;
            // korisnikDB.Opis = korisnikBDO.Opis;
            // JOS OPIS FALI U BAZI

            using (var t = db.Database.BeginTransaction())
            {
                try
                {
                    base.Insert(korisnikDB);
                    base.Complete();
                    t.Commit();
                }
                catch (Exception e)
                {
                    t.Rollback();
                    throw e;
                }
            }
        }
示例#3
0
        public async Task <IHttpActionResult> update(UserModels model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { error = true, message = Models.ErrorMessage.getErrorMessage(ModelState) }));
            }
            Boolean result = true;

            try
            {
                System.Web.HttpContext.Current.Application.Lock();
                DAL.User       nowUser    = _db.Users.Where(p => p.userID == model.userID).First();
                DAL.AspNetUser nowAccount = _db.AspNetUsers.Where(p => p.Id == nowUser.userID).First();
                //DAL.User gen = new DAL.User();
                nowUser.titleNameID = (int)model.titleNameID;
                nowUser.personalID  = model.personalID;
                nowUser.firstname   = model.firstname;
                nowUser.lastname    = model.lastname;
                nowUser.userTypeID  = (int)model.userTypeID;
                nowUser.status      = (int)model.status;
                nowUser.commanderID = model.commanderID;
                nowUser.personalID  = model.personalID;
                nowAccount.Email    = model.email;


                _db.SaveChanges();
                System.Web.HttpContext.Current.Application.UnLock();
            }
            catch (Exception e)
            {
                result = false;
            }

            return(Json(new { result = result }));
        }
示例#4
0
        public string checkUserRole()
        {
            string userId = User.Identity.GetUserId();

            DAL.AspNetUser user = db.AspNetUsers.Find(userId);
            string         role = user.AspNetRoles.ElementAt(0).Id;

            return(role);
        }
示例#5
0
 public ActionResult EditAdminBan(string id)
 {
     if (id == null)
     {
         return(RedirectToAction("CustomError", "Home", new { errorName = "This administrator does not exist.", errorMessage = "The administrator may have been removed or did not exist." }));
     }
     DAL.AspNetUser aspNetUser = db.AspNetUsers.Find(id);
     if (aspNetUser == null)
     {
         return(RedirectToAction("CustomError", "Home", new { errorName = "This administrator does not exist.", errorMessage = "The administrator may have been removed or did not exist." }));
     }
     ViewBag.AID = new SelectList(db.AvatarPaths, "ID", "AvatarName", aspNetUser.AID);
     return(View(aspNetUser));
 }
示例#6
0
        public ActionResult EditAdminBan(DAL.AspNetUser aspNetUser)
        {
            DAL.AspNetUser user;

            try
            {
                user = db.AspNetUsers.Find(aspNetUser.Id);
            }
            catch
            {
                return(RedirectToAction("CustomError", "Home", new { errorName = "This administrator does not exist.", errorMessage = "The administrator may have been removed or did not exist." }));
            }


            user.LockoutEndDateUtc = aspNetUser.LockoutEndDateUtc;


            db.SaveChanges();


            return(RedirectToAction("AllAdmin"));
        }
示例#7
0
        public async Task <IHttpActionResult> getUser(string userId)
        {
            System.Web.HttpContext.Current.Application.Lock();
            DAL.User       user       = _db.Users.Find(userId);
            DAL.AspNetUser aspNetUser = _db.AspNetUsers.Find(userId);

            var daoUser = new
            {
                titleNameID = user.titleNameID,
                personalID  = user.personalID,
                firstname   = user.firstname,
                lastname    = user.lastname,
                userTypeID  = user.userTypeID,
                commanderID = user.commanderID,
                email       = aspNetUser.Email,
                status      = user.status,
                titilename  = user.TitleName.titleName1
            };

            System.Web.HttpContext.Current.Application.UnLock();
            return(Json(daoUser));
        }