예제 #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);
        }
예제 #2
0
        public ServerResult <User> getOrCreate(User entity, bool withMsg = false)
        {
            ServerResult <User> sr = getByUniqueParams(entity, withMsg);

            if (!sr.success)
            {
                sr.succeed();
                sr = create(entity);
            }
            return(sr);
        }