コード例 #1
0
ファイル: UserRepo.cs プロジェクト: hamkairama/Tourismpedia
        public ResultStatus ChangePassword(int id, string oldPassword, string newPassword)
        {
            try
            {
                TOURIS_TM_USER user = _ctx.TOURIS_TM_USER.Find(id);

                if (user.PASSWORD == oldPassword)
                {
                    user.LAST_MODIFIED_TIME = DateTime.Now;
                    user.LAST_MODIFIED_BY   = user.USER_ID;
                    user.PASSWORD           = newPassword;

                    _ctx.Entry(user).State = EntityState.Modified;
                    _ctx.SaveChanges();
                    rs.SetSuccessStatus("Change password has been success");
                }
                else
                {
                    rs.SetErrorStatus("Old password is not match");
                }
            }
            catch (Exception ex)
            {
                rs.SetErrorStatus(ex.Message);
            }

            return(rs);
        }
コード例 #2
0
        public ApiGridResponse EditDataUser(TOURIS_TV_USER userView)
        {
            ApiGridResponse res = new ApiGridResponse();
            ResultStatus    rs  = new ResultStatus();

            try
            {
                using (TourismpediaEntities tourisdb = new TourismpediaEntities())
                {
                    TOURIS_TM_USER user = tourisdb.TOURIS_TM_USER.Find(userView.ID);
                    user.USER_NAME          = userView.USER_NAME;
                    user.USER_MAIL          = userView.USER_MAIL;
                    user.LAST_MODIFIED_BY   = userView.LAST_MODIFIED_BY;
                    user.LAST_MODIFIED_TIME = userView.LAST_MODIFIED_TIME;

                    tourisdb.Entry(user).State = EntityState.Modified;
                    tourisdb.SaveChanges();
                    rs.SetSuccessStatus();
                }
                res = ResGetDataTable(new object[] { rs }, null);
            }
            catch (Exception ex)
            {
                res = ResGetDataTable(null, ex);
            }

            return(res);
        }
コード例 #3
0
        public ApiGridResponse InsertDataUser(TOURIS_TV_USER userView)
        {
            ApiGridResponse res = new ApiGridResponse();
            ResultStatus    rs  = new ResultStatus();

            try
            {
                TOURIS_TM_USER user = new TOURIS_TM_USER();
                using (TourismpediaEntities tourisdb = new TourismpediaEntities())
                {
                    user.USER_NAME    = userView.USER_NAME;
                    user.USER_MAIL    = userView.USER_MAIL;
                    user.CREATED_BY   = userView.CREATED_BY;
                    user.CREATED_TIME = userView.CREATED_TIME;

                    tourisdb.TOURIS_TM_USER.Add(user);
                    tourisdb.SaveChanges();
                    rs.SetSuccessStatus();
                }
                res = ResGetDataTable(new object[] { rs }, null);
            }
            catch (Exception ex)
            {
                res = ResGetDataTable(null, ex);
            }

            return(res);
        }
コード例 #4
0
ファイル: UserRepo.cs プロジェクト: hamkairama/Tourismpedia
        private ResultStatus AddUser(TOURIS_TM_USER user, ref int userIdId)
        {
            _ctx.TOURIS_TM_USER.Add(user);
            _ctx.SaveChanges();

            userIdId = _ctx.TOURIS_TM_USER.Where(x => x.USER_MAIL == user.USER_MAIL).FirstOrDefault().ID;
            rs.SetSuccessStatus();

            return(rs);
        }
コード例 #5
0
ファイル: UserRepo.cs プロジェクト: hamkairama/Tourismpedia
        private ResultStatus EditUser(TOURIS_TM_USER user, ref int userProfileId)
        {
            TOURIS_TM_USER userNew = _ctx.TOURIS_TM_USER.Find(user.ID);

            userNew.USER_ID            = user.USER_ID;
            userNew.USER_NAME          = user.USER_NAME;
            userNew.USER_MAIL          = user.USER_MAIL;
            userNew.IS_SUPER_ADMIN     = user.IS_SUPER_ADMIN;
            userNew.LAST_MODIFIED_BY   = user.LAST_MODIFIED_BY;
            userNew.LAST_MODIFIED_TIME = user.LAST_MODIFIED_TIME;

            userProfileId = userNew.TOURIS_TM_USER_PROFILE.FirstOrDefault().ID;

            _ctx.Entry(userNew).State = System.Data.Entity.EntityState.Modified;
            _ctx.SaveChanges();
            rs.SetSuccessStatus();

            return(rs);
        }
コード例 #6
0
ファイル: UserRepo.cs プロジェクト: hamkairama/Tourismpedia
        public ResultStatus Delete(int id, string modifiedBy, DateTime modifiedTime)
        {
            try
            {
                TOURIS_TM_USER user = _ctx.TOURIS_TM_USER.Find(id);
                user.LAST_MODIFIED_TIME = modifiedTime;
                user.LAST_MODIFIED_BY   = modifiedBy;
                user.ROW_STATUS         = eStat.fg.NotActive;

                _ctx.Entry(user).State = EntityState.Modified;
                _ctx.SaveChanges();
                rs.SetSuccessStatus();
            }
            catch (Exception ex)
            {
                rs.SetErrorStatus(ex.Message);
            }

            return(rs);
        }
コード例 #7
0
ファイル: UserRepo.cs プロジェクト: hamkairama/Tourismpedia
        public ResultStatus Edit(TOURIS_TM_USER user, TOURIS_TM_USER_PROFILE userProfile, List <TOURIS_TM_USER_PROFILE_SOSMED> userProfileSosmed)
        {
            using (var transaction = _ctx.Database.BeginTransaction())
            {
                try
                {
                    int userProfileId = 0;
                    rs = EditUser(user, ref userProfileId);

                    if (rs.IsSuccess && userProfile.ADDRESS != "")
                    {
                        userProfile.ID = userProfileId;
                        rs             = EditUserProfile(userProfile);
                    }

                    if (rs.IsSuccess && userProfileSosmed.Count > 0)
                    {
                        List <TOURIS_TM_USER_PROFILE_SOSMED> userProfileSosmedNew = new List <TOURIS_TM_USER_PROFILE_SOSMED>();
                        foreach (var item in userProfileSosmed)
                        {
                            item.USER_PROFILE_ID = userProfileId;
                            userProfileSosmedNew.Add(item);
                        }
                        rs = AddUserProfileSosmed(userProfileSosmedNew);
                    }
                    transaction.Commit();
                    rs.SetSuccessStatus();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    rs.SetErrorStatus(ex.Message);
                }
            }


            return(rs);
        }
コード例 #8
0
        public ApiGridResponse DeleteDataUser(TOURIS_TV_USER userView)
        {
            ApiGridResponse res = new ApiGridResponse();
            ResultStatus    rs  = new ResultStatus();

            try
            {
                using (TourismpediaEntities tourisdb = new TourismpediaEntities())
                {
                    TOURIS_TM_USER user = tourisdb.TOURIS_TM_USER.Find(userView.ID);

                    tourisdb.TOURIS_TM_USER.Remove(user);
                    tourisdb.SaveChanges();
                    rs.SetSuccessStatus();
                }
                res = ResGetDataTable(new object[] { rs }, null);
            }
            catch (Exception ex)
            {
                res = ResGetDataTable(null, ex);
            }

            return(res);
        }
コード例 #9
0
ファイル: UserRepo.cs プロジェクト: hamkairama/Tourismpedia
        public TOURIS_TM_USER Login(string email, string password)
        {
            TOURIS_TM_USER user = _ctx.TOURIS_TM_USER.Where(x => x.USER_MAIL == email && x.PASSWORD == password).FirstOrDefault();

            return(user);
        }
コード例 #10
0
        public IHttpActionResult Login(CUSTOM_LOGIN login)
        {
            ApiResData res = new ApiResData();

            try
            {
                if (!ModelState.IsValid)
                {
                    rs.SetErrorStatus(eFunc.fg.SFailed);
                    resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.DataNf, new Exception(eFunc.fg.DataIsntValid)));
                    return(Content(HttpStatusCode.NotFound, resObj));
                }

                TOURIS_TM_USER user     = repo.Login(login.Email, login.Password);
                TOURIS_TV_USER userView = new TOURIS_TV_USER();

                if (user != null)
                {
                    userView.ID                 = user.ID;
                    userView.USER_ID            = user.USER_ID;
                    userView.USER_MAIL          = user.USER_MAIL;
                    userView.USER_NAME          = user.USER_NAME;
                    userView.IS_SUPER_ADMIN     = user.IS_SUPER_ADMIN;
                    userView.LAST_LOGIN         = user.LAST_LOGIN;
                    userView.PASSWORD           = user.PASSWORD;
                    userView.PHOTO_PATH         = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().PHOTO_PATH;
                    userView.GENDER             = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().GENDER;
                    userView.BORN               = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().BORN;
                    userView.ADDRESS            = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().ADDRESS;
                    userView.DESCRIPTION        = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().DESCRIPTION;
                    userView.JOB                = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().JOB;
                    userView.COMPANY            = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().COMPANY;
                    userView.HOBBY              = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().HOBBY;
                    userView.CREATED_BY         = user.CREATED_BY;
                    userView.CREATED_TIME       = user.CREATED_TIME;
                    userView.LAST_MODIFIED_BY   = user.LAST_MODIFIED_BY;
                    userView.LAST_MODIFIED_TIME = user.LAST_MODIFIED_TIME;

                    if (user.TOURIS_TM_USER_PROFILE != null)
                    {
                        TOURIS_TV_USER_PROFILE userProfileView = new TOURIS_TV_USER_PROFILE();
                        userProfileView.ID                 = user.ID;
                        userProfileView.USER_ID_ID         = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().USER_ID_ID;
                        userProfileView.PHOTO_PATH         = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().PHOTO_PATH;
                        userProfileView.GENDER             = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().GENDER;
                        userProfileView.BORN               = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().BORN;
                        userProfileView.ADDRESS            = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().ADDRESS;
                        userProfileView.DESCRIPTION        = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().DESCRIPTION;
                        userProfileView.JOB                = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().JOB;
                        userProfileView.COMPANY            = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().COMPANY;
                        userProfileView.HOBBY              = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().HOBBY;
                        userProfileView.CREATED_BY         = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().CREATED_BY;
                        userProfileView.CREATED_TIME       = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().CREATED_TIME;
                        userProfileView.LAST_MODIFIED_BY   = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().LAST_MODIFIED_BY;
                        userProfileView.LAST_MODIFIED_TIME = user.TOURIS_TM_USER_PROFILE.FirstOrDefault().LAST_MODIFIED_TIME;

                        if (user.TOURIS_TM_USER_PROFILE.FirstOrDefault().TOURIS_TM_USER_PROFILE_SOSMED.Count > 0)
                        {
                            foreach (var itemSosmed in user.TOURIS_TM_USER_PROFILE.FirstOrDefault().TOURIS_TM_USER_PROFILE_SOSMED)
                            {
                                TOURIS_TV_USER_PROFILE_SOSMED userProfileSosmedView = new TOURIS_TV_USER_PROFILE_SOSMED();
                                userProfileSosmedView.ID = user.ID;
                                userProfileSosmedView.USER_PROFILE_ID    = itemSosmed.USER_PROFILE_ID;
                                userProfileSosmedView.SOSMED_NAME        = itemSosmed.SOSMED_NAME;
                                userProfileSosmedView.SOSMED_PATH        = itemSosmed.SOSMED_PATH;
                                userProfileSosmedView.CREATED_BY         = itemSosmed.CREATED_BY;
                                userProfileSosmedView.CREATED_TIME       = itemSosmed.CREATED_TIME;
                                userProfileSosmedView.LAST_MODIFIED_BY   = itemSosmed.LAST_MODIFIED_BY;
                                userProfileSosmedView.LAST_MODIFIED_TIME = itemSosmed.LAST_MODIFIED_TIME;

                                userProfileView.TOURIS_TV_USER_PROFILE_SOSMED.Add(userProfileSosmedView);
                            }
                        }

                        userView.TOURIS_TV_USER_PROFILE.Add(userProfileView);
                    }

                    rs.SetSuccessStatus();
                }
                resObj = JObject.FromObject(res.ResGetDataTable(new object[] { userView }, null));

                return(Content(HttpStatusCode.OK, resObj));
            }
            catch (Exception ex)
            {
                rs.SetErrorStatus(ex.Message);
                resObj = JObject.FromObject(res.ResGetDataTable(new object[] { rs }, new Exception(eFunc.fg.DataNf)));
                return(Content(HttpStatusCode.BadRequest, resObj));
            }
        }
コード例 #11
0
        public IHttpActionResult Edit(TOURIS_TV_USER userView)
        {
            ApiResData             res         = new ApiResData();
            TOURIS_TM_USER         user        = new TOURIS_TM_USER();
            TOURIS_TM_USER_PROFILE userProfile = new TOURIS_TM_USER_PROFILE();
            List <TOURIS_TM_USER_PROFILE_SOSMED> userProfileSosmeds = new List <TOURIS_TM_USER_PROFILE_SOSMED>();

            try
            {
                //if (!ModelState.IsValid)
                //{
                //    rs.SetErrorStatus(eFunc.fg.SFailed);
                //    resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Edit, new Exception(eFunc.fg.DataIsntValid)));
                //    return Content(HttpStatusCode.NotFound, resObj);
                //}

                if (userView != null)
                {
                    user.ID                 = userView.ID;
                    user.USER_ID            = userView.USER_ID;
                    user.USER_MAIL          = userView.USER_MAIL;
                    user.USER_NAME          = userView.USER_NAME;
                    user.IS_SUPER_ADMIN     = userView.IS_SUPER_ADMIN;
                    user.LAST_MODIFIED_BY   = userView.LAST_MODIFIED_BY;
                    user.LAST_MODIFIED_TIME = userView.LAST_MODIFIED_TIME;

                    if (userView.TOURIS_TV_USER_PROFILE != null)
                    {
                        userProfile.USER_ID_ID = userView.ID;
                        if (userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().PHOTO_PATH != null)
                        {
                            userProfile.PHOTO_PATH = userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().PHOTO_PATH;
                        }
                        userProfile.GENDER             = userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().GENDER;
                        userProfile.BORN               = userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().BORN;
                        userProfile.ADDRESS            = userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().ADDRESS;
                        userProfile.DESCRIPTION        = userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().DESCRIPTION;
                        userProfile.JOB                = userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().JOB;
                        userProfile.COMPANY            = userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().COMPANY;
                        userProfile.HOBBY              = userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().HOBBY;
                        userProfile.LAST_MODIFIED_BY   = userView.LAST_MODIFIED_BY;
                        userProfile.LAST_MODIFIED_TIME = userView.LAST_MODIFIED_TIME;

                        if (userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().TOURIS_TV_USER_PROFILE_SOSMED.Count > 0)
                        {
                            foreach (var itemSosmed in userView.TOURIS_TV_USER_PROFILE.FirstOrDefault().TOURIS_TV_USER_PROFILE_SOSMED)
                            {
                                TOURIS_TM_USER_PROFILE_SOSMED userProfileSosmed = new TOURIS_TM_USER_PROFILE_SOSMED();
                                userProfileSosmed.ID = user.ID;
                                userProfileSosmed.USER_PROFILE_ID    = itemSosmed.USER_PROFILE_ID;
                                userProfileSosmed.SOSMED_NAME        = itemSosmed.SOSMED_NAME;
                                userProfileSosmed.SOSMED_PATH        = itemSosmed.SOSMED_PATH;
                                userProfileSosmed.CREATED_BY         = itemSosmed.CREATED_BY;
                                userProfileSosmed.CREATED_TIME       = itemSosmed.CREATED_TIME;
                                userProfileSosmed.LAST_MODIFIED_BY   = itemSosmed.LAST_MODIFIED_BY;
                                userProfileSosmed.LAST_MODIFIED_TIME = itemSosmed.LAST_MODIFIED_TIME;

                                userProfileSosmeds.Add(userProfileSosmed);
                            }
                        }
                    }
                }

                rs = repo.Edit(user, userProfile, userProfileSosmeds);
                if (rs.IsSuccess)
                {
                    rs.SetSuccessStatus();
                }
                else
                {
                    rs.SetErrorStatus(eFunc.fg.SFailed);
                }

                resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Edit, null));
                return(Content(HttpStatusCode.OK, resObj));
            }
            catch (Exception ex)
            {
                rs.SetErrorStatus(ex.Message);
                resObj = JObject.FromObject(res.ResCUD(new object[] { rs }, eFunc.fg.Edit, new Exception(eFunc.fg.EFailed)));
                return(Content(HttpStatusCode.BadRequest, resObj));
            }
        }