Exemple #1
0
        private ResultStatus AddUserProfile(TOURIS_TM_USER_PROFILE userProfile, ref int userProfileId)
        {
            _ctx.TOURIS_TM_USER_PROFILE.Add(userProfile);
            _ctx.SaveChanges();

            userProfileId = _ctx.TOURIS_TM_USER_PROFILE.Where(x => x.USER_ID_ID == userProfile.USER_ID_ID).FirstOrDefault().ID;
            rs.SetSuccessStatus();

            return(rs);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        private ResultStatus EditUserProfile(TOURIS_TM_USER_PROFILE userProfile)
        {
            TOURIS_TM_USER_PROFILE userProfileNew = _ctx.TOURIS_TM_USER_PROFILE.Find(userProfile.ID);

            userProfileNew.ADDRESS     = userProfile.ADDRESS;
            userProfileNew.BORN        = userProfile.BORN;
            userProfileNew.DESCRIPTION = userProfile.DESCRIPTION;
            userProfileNew.GENDER      = userProfile.GENDER;
            userProfileNew.COMPANY     = userProfile.COMPANY;
            if (userProfile.PHOTO_PATH != null)
            {
                userProfileNew.PHOTO_PATH = userProfile.PHOTO_PATH;
            }
            userProfileNew.HOBBY              = userProfile.HOBBY;
            userProfileNew.LAST_MODIFIED_BY   = userProfile.LAST_MODIFIED_BY;
            userProfileNew.LAST_MODIFIED_TIME = userProfile.LAST_MODIFIED_TIME;

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

            return(rs);
        }
        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));
            }
        }