Exemplo n.º 1
0
        public ServerResult <User> create(User entity, bool withMsg = true)
        {
            ServerResult <User> sr = passCreateGurd(entity);

            if (!sr.success)
            {
                return(sr);
            }
            sr = getByUniqueParams(entity, withMsg);
            if (sr.success)
            {
                sr.error.addMessage(HttpError.entityExist, withMsg);
                sr.fail();
            }
            else
            {
                sr.succeed();
                sr.result       = new User();
                sr.result.apiId = entity.apiId;
                if (sr.result.apiId == null)
                {
                    sr.result.apiId = Helper.Helper.RandomId();
                }
                sr.result.name     = entity.name;
                sr.result.email    = entity.email;
                sr.result.password = entity.password;
                sr.error.addInfo(HttpError.getAddIdIntoTable(TabelList.User, sr.result.apiId));
                db.Add(sr.result);
                db.SaveChanges();
            }
            return(sr);
        }
Exemplo n.º 2
0
        public ServerResult <User> getById(string id, bool withMsg = true)
        {
            ServerResult <User> sr = ServerResult <User> .create();

            try{
                sr.result = db.User.Find(id);
                if (sr.result == null)
                {
                    sr.error.addMessage(HttpError.getNoTableEntryForValue(TabelList.GroupRoleLink, "id", id), withMsg);
                    sr.fail();
                }
            } catch {
                sr.error.addMessage(HttpError.getNoTableEntryForValue(TabelList.User, "id", id), withMsg);
                sr.fail();
                return(sr);
            };
            return(sr);
        }
Exemplo n.º 3
0
        public ServerResult <User> passCreateGurd(User entity, bool withMsg = true)
        {
            ServerResult <User> sr = ServerResult <User> .create();

            sr.result = entity;
            if (sr.result == null)
            {
                sr.error.addMessage(HttpError.getProvideNoEntity(TabelList.User), withMsg);
                sr.fail();
                return(sr);
            }
            if (sr.result.email == null)
            {
                sr.error.addMessage(HttpError.getFieldsNotProvidedForTable(TabelList.User, "email"), withMsg);
                sr.fail();
                return(sr);
            }
            return(sr);
        }
Exemplo n.º 4
0
        public ServerResult <User> getByEmail(string email, bool withMsg = true)
        {
            ServerResult <User> sr = ServerResult <User> .create();

            try{
                sr.result = db.User.Where(el => el.email == email).First();
            } catch {
                sr.error.addMessage(HttpError.getNoTableEntryForValue(TabelList.User, "email", email), withMsg);
                sr.fail();
                return(sr);
            };
            return(sr);
        }
Exemplo n.º 5
0
        public ServerResult <Group> passCreateGurd(Group entity, bool withMsg = true)
        {
            ServerResult <Group> sr = ServerResult <Group> .create();

            sr.result = entity;
            if (sr.result == null)
            {
                sr.error.addMessage(HttpError.getProvideNoEntity(TabelList.Group), withMsg);
                sr.fail();
                return(sr);
            }
            return(sr);
        }
Exemplo n.º 6
0
        public ServerResult <Group> getByUniqueParams(Group entity, bool withMsg = true)
        {
            ServerResult <Group> sr = ServerResult <Group> .create();

            if (entity.apiId != null)
            {
                return(getById(entity.apiId, withMsg));
            }
            string[] parameter = { "id" };
            sr.error.addMessage(Helper.HttpError.getNoUniqueParameter("Group", parameter));
            sr.fail();
            return(sr);
        }
Exemplo n.º 7
0
        public ServerResult <List <Group> > search(SearchModel search, bool withMsg = true)
        {
            ServerResult <List <Group> > sr = ServerResult <List <Group> > .create();

            sr.result = new List <Group>();
            try {
                foreach (Group group in db.Group.Where(el => el.name.Contains(search.searchString)).ToList())
                {
                    sr.result.Add(group);
                }
                ;
            } catch {
                sr.fail();
                sr.error.addMessage(Helper.HttpError.getNoElementFound(TabelList.Group));
            }
            return(sr);
        }
Exemplo n.º 8
0
        public ServerResult <User> search(User entity, bool withMsg = true)
        {
            ServerResult <User> sr = passCreateGurd(entity);

            if (!sr.success)
            {
                return(sr);
            }
            User result;

            Helper.Helper.print("TODO: implement search");
            result = db.User.Find(entity.apiId);
            if (result == null)
            {
                sr.error.addMessage(HttpError.getNoTableEntryForValue("User", "id", entity.apiId), withMsg);
                sr.fail();
                return(sr);
            }
            sr.result = result;
            return(sr);
        }
Exemplo n.º 9
0
        public ServerResult <User> update(User entity, bool withMsg = true)
        {
            ServerResult <User> sr = passCreateGurd(entity);

            if (!sr.success)
            {
                return(sr);
            }
            User result;

            result = db.User.Find(entity.apiId);
            if (result == null)
            {
                sr.error.addMessage(HttpError.getNoTableEntryForValue("User", "id", entity.apiId), withMsg);
                sr.fail();
                return(sr);
            }
            sr.error.addInfo(HttpError.getAddIdIntoTable(TabelList.User, sr.result.apiId));
            db.Update(result);
            db.SaveChanges();
            sr.result = result;
            return(sr);
        }