Пример #1
0
        public IHttpActionResult PutUserRole(int id, UserRole userRole)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userRole.UserRoleID)
            {
                return(BadRequest());
            }

            db.Entry(userRole).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserRoleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public IHttpActionResult PutCustomer(int id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer.CustomerID)
            {
                return(BadRequest());
            }

            db.Entry(customer).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
 public void Update(UserRole userRole)
 {
     using (CRContext db = new CRContext())
     {
         db.UserRoles.Attach(userRole);
         db.Entry(userRole).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Пример #4
0
 public void Insert(User user)
 {
     using (CRContext db = new CRContext())
     {
         db.Users.Add(user);
         db.UserRoles.Attach(user.UserRole);
         db.Entry(user.UserRole).State = System.Data.Entity.EntityState.Unchanged;
         db.SaveChanges();
     }
 }
Пример #5
0
        public IHttpActionResult PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.UserID)
            {
                return(BadRequest());
            }

            if (!String.IsNullOrEmpty(user.SecretPhrase))
            {
                user.SecretPhrase = new Cypher().Encrypt(user.SecretPhrase);
            }

            user.Password = new Cypher().Encrypt(user.Password);

            db.UserRoles.Attach(user.UserRole);
            user.UserRoleID      = user.UserRole.UserRoleID;
            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #6
0
        public IHttpActionResult PutMenu(int id, Menu menu)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != menu.MenuID)
            {
                return(BadRequest());
            }

            Menu parentMenu = (menu.ParentMenu != null ? menu.ParentMenu : null);

            if (parentMenu != null)
            {
                db.Menus.Attach(menu.ParentMenu);
                menu.ParentMenuID = menu.ParentMenu.ParentMenuID;
            }
            db.Entry(menu).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MenuExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #7
0
 public void Insert(Menu menu)
 {
     using (CRContext db = new CRContext())
     {
         db.Menus.Add(menu);
         Menu parentMenu = (menu.ParentMenu != null ? menu.ParentMenu : null);
         if (parentMenu != null)
         {
             db.Menus.Attach(parentMenu);
             db.Entry(menu.ParentMenu).State = EntityState.Unchanged;
         }
         db.SaveChanges();
     }
 }
Пример #8
0
        public void Update(Menu menu)
        {
            using (CRContext db = new CRContext())
            {
                Menu parentMenu = (menu.ParentMenu != null ? menu.ParentMenu : null);
                if (parentMenu != null)
                {
                    db.Menus.Attach(menu.ParentMenu);
                    menu.ParentMenuID = menu.ParentMenu.ParentMenuID;
                }

                db.Entry(menu).State = EntityState.Modified;
                db.SaveChanges();
            }
        }