コード例 #1
0
        public HttpResponseMessage UpdateCurrentUserBranch(Entities.MstUserBranch objUserBranch)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userBranch = from d in db.MstUserBranches
                                     where d.BranchId == objUserBranch.BranchId &&
                                     d.UserId == currentUserId
                                     select d;

                    if (userBranch.Any())
                    {
                        var updateCurrentBranch = currentUser.FirstOrDefault();
                        updateCurrentBranch.CompanyId       = userBranch.FirstOrDefault().MstBranch.CompanyId;
                        updateCurrentBranch.BranchId        = userBranch.FirstOrDefault().BranchId;
                        updateCurrentBranch.UpdatedById     = currentUserId;
                        updateCurrentBranch.UpdatedDateTime = DateTime.Now;

                        db.SubmitChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. Branch you selected was not found."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
コード例 #2
0
        public HttpResponseMessage AddUserBranch(Entities.MstUserBranch objUserBranch, String userId)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userBranches = from d in db.MstUserForms
                                       where d.UserId == currentUserId &&
                                       d.SysForm.FormName.Equals("UserDetail")
                                       select d;

                    if (userBranches.Any())
                    {
                        if (userBranches.FirstOrDefault().CanAdd)
                        {
                            var user = from d in db.MstUsers
                                       where d.Id == Convert.ToInt32(userId)
                                       select d;

                            if (user.Any())
                            {
                                if (!user.FirstOrDefault().IsLocked)
                                {
                                    Data.MstUserBranch newUserBranch = new Data.MstUserBranch
                                    {
                                        UserId   = Convert.ToInt32(userId),
                                        BranchId = objUserBranch.BranchId
                                    };

                                    db.MstUserBranches.InsertOnSubmit(newUserBranch);
                                    db.SubmitChanges();

                                    return(Request.CreateResponse(HttpStatusCode.OK));
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "You cannot add new user branch if the current user detail is locked."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "These current user details are not found in the server. Please add new user first before proceeding."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add user branch."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this user page."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
コード例 #3
0
        public HttpResponseMessage UpdateUserBranch(Entities.MstUserBranch objUserBranch, String id, String userId)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userBranches = from d in db.MstUserForms
                                       where d.UserId == currentUserId &&
                                       d.SysForm.FormName.Equals("UserDetail")
                                       select d;

                    if (userBranches.Any())
                    {
                        if (userBranches.FirstOrDefault().CanEdit)
                        {
                            var user = from d in db.MstUsers
                                       where d.Id == Convert.ToInt32(userId)
                                       select d;

                            if (user.Any())
                            {
                                if (!user.FirstOrDefault().IsLocked)
                                {
                                    var userBranch = from d in db.MstUserBranches
                                                     where d.Id == Convert.ToInt32(id)
                                                     select d;

                                    if (userBranch.Any())
                                    {
                                        String oldObject = at.GetObjectString(userBranch.FirstOrDefault());

                                        var updateUserBranch = userBranch.FirstOrDefault();
                                        updateUserBranch.BranchId = objUserBranch.BranchId;
                                        db.SubmitChanges();

                                        String newObject = at.GetObjectString(userBranch.FirstOrDefault());
                                        at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, oldObject, newObject);

                                        return(Request.CreateResponse(HttpStatusCode.OK));
                                    }
                                    else
                                    {
                                        return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found. These user branch details are not found in the server."));
                                    }
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "You cannot edit and update user branch if the current user detail is locked."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "These current user details are not found in the server. Please add new user first before proceeding."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to edit and update user branch."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this user page."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }