コード例 #1
0
        public HttpResponseMessage postMstUserForm(Entities.MstUserForm userForm)
        {
            try
            {
                Data.MstUserForm newUserForm = new Data.MstUserForm();
                newUserForm.FormId      = userForm.FormId;
                newUserForm.UserId      = userForm.UserId;
                newUserForm.CanDelete   = userForm.CanDelete;
                newUserForm.CanAdd      = userForm.CanAdd;
                newUserForm.CanLock     = userForm.CanLock;
                newUserForm.CanUnlock   = userForm.CanUnlock;
                newUserForm.CanPrint    = userForm.CanPrint;
                newUserForm.CanPreview  = userForm.CanPreview;
                newUserForm.CanEdit     = userForm.CanEdit;
                newUserForm.CanTender   = userForm.CanTender;
                newUserForm.CanDiscount = userForm.CanDiscount;
                newUserForm.CanView     = userForm.CanView;
                newUserForm.CanSplit    = userForm.CanSplit;
                newUserForm.CanCancel   = userForm.CanCancel;
                newUserForm.CanReturn   = userForm.CanReturn;
                db.MstUserForms.InsertOnSubmit(newUserForm);
                db.SubmitChanges();

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
コード例 #2
0
        public Int32 postUserForm()
        {
            try
            {
                Data.MstUserForm newUserForm = new Data.MstUserForm();
                newUserForm.FormId      = FormId();
                newUserForm.UserId      = UserId();
                newUserForm.CanDelete   = false;
                newUserForm.CanAdd      = false;
                newUserForm.CanLock     = false;
                newUserForm.CanUnlock   = false;
                newUserForm.CanPrint    = false;
                newUserForm.CanPreview  = false;
                newUserForm.CanEdit     = false;
                newUserForm.CanTender   = false;
                newUserForm.CanDiscount = false;
                newUserForm.CanView     = false;
                newUserForm.CanSplit    = false;
                newUserForm.CanCancel   = false;
                newUserForm.CanReturn   = false;
                db.MstUserForms.InsertOnSubmit(newUserForm);
                db.SubmitChanges();

                return(newUserForm.Id);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
コード例 #3
0
        public HttpResponseMessage copyRightsUserForms(String name, String userId)
        {
            try
            {
                var userForms = from d in db.MstUserForms
                                where d.MstUser.UserName == name
                                select new Models.MstUserForm
                {
                    Id          = d.Id,
                    UserId      = d.UserId,
                    User        = d.MstUser.FullName,
                    FormId      = d.FormId,
                    Form        = d.SysForm.FormName,
                    Particulars = d.SysForm.Particulars,
                    CanAdd      = d.CanAdd,
                    CanEdit     = d.CanEdit,
                    CanDelete   = d.CanDelete,
                    CanLock     = d.CanLock,
                    CanUnlock   = d.CanUnlock,
                    CanPrint    = d.CanPrint
                };

                if (userForms.Any())
                {
                    var deleteUserForms = from d in db.MstUserForms where d.UserId == Convert.ToInt32(userId) select d;

                    db.MstUserForms.DeleteAllOnSubmit(deleteUserForms.ToList());
                    db.SubmitChanges();

                    foreach (var userForm in userForms)
                    {
                        Data.MstUserForm newUserForm = new Data.MstUserForm();

                        newUserForm.UserId    = Convert.ToInt32(userId);
                        newUserForm.FormId    = userForm.FormId;
                        newUserForm.CanAdd    = userForm.CanAdd;
                        newUserForm.CanEdit   = userForm.CanEdit;
                        newUserForm.CanDelete = userForm.CanDelete;
                        newUserForm.CanLock   = userForm.CanLock;
                        newUserForm.CanUnlock = userForm.CanUnlock;
                        newUserForm.CanPrint  = userForm.CanPrint;

                        db.MstUserForms.InsertOnSubmit(newUserForm);
                        db.SubmitChanges();
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
コード例 #4
0
        public HttpResponseMessage copyRightsUserForms(String name, String userId)
        {
            try
            {
                var userForms = from d in db.MstUserForms
                                where d.MstUser.UserName == name
                                select new Models.MstUserForm
                                {
                                    Id = d.Id,
                                    UserId = d.UserId,
                                    User = d.MstUser.FullName,
                                    FormId = d.FormId,
                                    Form = d.SysForm.FormName,
                                    Particulars = d.SysForm.Particulars,
                                    CanAdd = d.CanAdd,
                                    CanEdit = d.CanEdit,
                                    CanDelete = d.CanDelete,
                                    CanLock = d.CanLock,
                                    CanUnlock = d.CanUnlock,
                                    CanPrint = d.CanPrint
                                };

                if (userForms.Any())
                {
                    var deleteUserForms = from d in db.MstUserForms where d.UserId == Convert.ToInt32(userId) select d;

                    db.MstUserForms.DeleteAllOnSubmit(deleteUserForms.ToList());
                    db.SubmitChanges();

                    foreach (var userForm in userForms)
                    {
                        Data.MstUserForm newUserForm = new Data.MstUserForm();

                        newUserForm.UserId = Convert.ToInt32(userId);
                        newUserForm.FormId = userForm.FormId;
                        newUserForm.CanAdd = userForm.CanAdd;
                        newUserForm.CanEdit = userForm.CanEdit;
                        newUserForm.CanDelete = userForm.CanDelete;
                        newUserForm.CanLock = userForm.CanLock;
                        newUserForm.CanUnlock = userForm.CanUnlock;
                        newUserForm.CanPrint = userForm.CanPrint;

                        db.MstUserForms.InsertOnSubmit(newUserForm);
                        db.SubmitChanges();
                    }

                    return Request.CreateResponse(HttpStatusCode.OK);
                }
                else
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }
            }
            catch
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
コード例 #5
0
        public HttpResponseMessage AddUserForm(Models.MstUserForm objUserForm)
        {
            try
            {
                var currentUser = from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d;
                if (currentUser.Any())
                {
                    if (currentUser.FirstOrDefault().UserTypeId != 3)
                    {
                        Data.MstUserForm newUserForm = new Data.MstUserForm
                        {
                            UserId    = objUserForm.UserId,
                            FormId    = objUserForm.FormId,
                            CanAdd    = objUserForm.CanAdd,
                            CanEdit   = objUserForm.CanEdit,
                            CanUpdate = objUserForm.CanUpdate,
                            CanDelete = objUserForm.CanDelete
                        };

                        db.MstUserForms.InsertOnSubmit(newUserForm);
                        db.SubmitChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add user forms."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. No current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server. " + e.Message));
            }
        }
コード例 #6
0
        public Int32 insertUserForm(Models.MstUserForm userForm)
        {
            try
            {
                Data.MstUserForm newUserForm = new Data.MstUserForm();
                newUserForm.UserId    = userForm.UserId;
                newUserForm.FormId    = userForm.FormId;
                newUserForm.CanAdd    = userForm.CanAdd;
                newUserForm.CanEdit   = userForm.CanEdit;
                newUserForm.CanDelete = userForm.CanDelete;
                newUserForm.CanLock   = userForm.CanLock;
                newUserForm.CanUnlock = userForm.CanUnlock;
                newUserForm.CanPrint  = userForm.CanPrint;

                db.MstUserForms.InsertOnSubmit(newUserForm);
                db.SubmitChanges();

                return(newUserForm.Id);
            }
            catch
            {
                return(0);
            }
        }
コード例 #7
0
        public Int32 insertUserForm(Models.MstUserForm userForm)
        {
            try
            {
                Data.MstUserForm newUserForm = new Data.MstUserForm();
                newUserForm.UserId = userForm.UserId;
                newUserForm.FormId = userForm.FormId;
                newUserForm.CanAdd = userForm.CanAdd;
                newUserForm.CanEdit = userForm.CanEdit;
                newUserForm.CanDelete = userForm.CanDelete;
                newUserForm.CanLock = userForm.CanLock;
                newUserForm.CanUnlock = userForm.CanUnlock;
                newUserForm.CanPrint = userForm.CanPrint;

                db.MstUserForms.InsertOnSubmit(newUserForm);
                db.SubmitChanges();

                return newUserForm.Id;
            }
            catch
            {
                return 0;
            }
        }
コード例 #8
0
        public int Post(Models.MstUserForm userForm)
        {
            try
            {

                Data.MstUserForm newUserForm = new Data.MstUserForm();

                newUserForm.FormId = userForm.FormId;
                newUserForm.UserId = userForm.UserId;
                newUserForm.CanDelete = userForm.CanDelete;
                newUserForm.CanAdd = userForm.CanAdd;
                newUserForm.CanLock = userForm.CanLock;
                newUserForm.CanUnlock = userForm.CanUnlock;
                newUserForm.CanPrint = userForm.CanPrint;
                newUserForm.CanPreview = userForm.CanPreview;
                newUserForm.CanEdit = userForm.CanEdit;
                newUserForm.CanTender = userForm.CanTender;
                newUserForm.CanDiscount = userForm.CanDiscount;
                newUserForm.CanView = userForm.CanView;
                newUserForm.CanSplit = userForm.CanSplit;
                newUserForm.CanCancel = userForm.CanCancel;
                newUserForm.CanReturn = userForm.CanReturn;

                db.MstUserForms.InsertOnSubmit(newUserForm);
                db.SubmitChanges();

                return newUserForm.Id;
            }
            catch
            {
                return 0;
            }
        }
コード例 #9
0
        public HttpResponseMessage CopyRightsUserForms(String name, 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 userForms = from d in db.MstUserForms
                                    where d.UserId == currentUserId &&
                                    d.SysForm.FormName.Equals("UserDetail")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            Boolean canCopy         = false;
                            var     currentUserName = currentUser.FirstOrDefault().UserName;

                            if (currentUserName.Equals("admin"))
                            {
                                canCopy = true;
                            }
                            else
                            {
                                if (!name.Equals("admin"))
                                {
                                    canCopy = true;
                                }
                            }

                            if (canCopy)
                            {
                                var userFormSource = from d in db.MstUserForms
                                                     where d.MstUser.UserName.Equals(name)
                                                     //&& d.MstUser.IsLocked == true
                                                     select d;

                                if (userFormSource.Any())
                                {
                                    String oldObject = "[";

                                    var deleteUserForms = from d in db.MstUserForms
                                                          where d.UserId == Convert.ToInt32(userId)
                                                          select d;

                                    if (deleteUserForms.Any())
                                    {
                                        db.MstUserForms.DeleteAllOnSubmit(deleteUserForms.ToList());

                                        Int32 oldObjectCount = 0;
                                        foreach (var deleteUserForm in deleteUserForms)
                                        {
                                            oldObjectCount += 1;

                                            if (deleteUserForms.Count() == 1)
                                            {
                                                oldObject += at.GetObjectString(deleteUserForm);
                                            }
                                            else
                                            {
                                                if (oldObjectCount == deleteUserForms.Count())
                                                {
                                                    oldObject += at.GetObjectString(deleteUserForm);
                                                }
                                                else
                                                {
                                                    oldObject += at.GetObjectString(deleteUserForm) + ", ";
                                                }
                                            }
                                        }

                                        db.SubmitChanges();
                                    }

                                    oldObject += "]";

                                    String newObject      = "[";
                                    Int32  newObjectCount = 0;

                                    foreach (var userForm in userFormSource)
                                    {
                                        newObjectCount += 1;

                                        Data.MstUserForm newUserForm = new Data.MstUserForm
                                        {
                                            UserId    = Convert.ToInt32(userId),
                                            FormId    = userForm.FormId,
                                            CanAdd    = userForm.CanAdd,
                                            CanEdit   = userForm.CanEdit,
                                            CanDelete = userForm.CanDelete,
                                            CanLock   = userForm.CanLock,
                                            CanUnlock = userForm.CanUnlock,
                                            CanCancel = userForm.CanCancel,
                                            CanPrint  = userForm.CanPrint
                                        };

                                        db.MstUserForms.InsertOnSubmit(newUserForm);

                                        if (userFormSource.Count() == 1)
                                        {
                                            newObject += at.GetObjectString(newUserForm);
                                        }
                                        else
                                        {
                                            if (newObjectCount == userFormSource.Count())
                                            {
                                                newObject += at.GetObjectString(newUserForm);
                                            }
                                            else
                                            {
                                                newObject += at.GetObjectString(newUserForm) + ", ";
                                            }
                                        }
                                    }

                                    db.SubmitChanges();

                                    newObject += "]";
                                    at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, oldObject, newObject);

                                    return(Request.CreateResponse(HttpStatusCode.OK));
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "No user rights found."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.BadRequest, "No rights."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add user form."));
                        }
                    }
                    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."));
            }
        }
コード例 #10
0
        public HttpResponseMessage AddUserForm(Entities.MstUserForm objUserForm, 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 userForms = from d in db.MstUserForms
                                    where d.UserId == currentUserId &&
                                    d.SysForm.FormName.Equals("UserDetail")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.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.MstUserForm newUserForm = new Data.MstUserForm
                                    {
                                        UserId    = Convert.ToInt32(userId),
                                        FormId    = objUserForm.FormId,
                                        CanAdd    = objUserForm.CanAdd,
                                        CanEdit   = objUserForm.CanEdit,
                                        CanDelete = objUserForm.CanDelete,
                                        CanLock   = objUserForm.CanLock,
                                        CanUnlock = objUserForm.CanUnlock,
                                        CanCancel = objUserForm.CanCancel,
                                        CanPrint  = objUserForm.CanPrint
                                    };

                                    db.MstUserForms.InsertOnSubmit(newUserForm);
                                    db.SubmitChanges();

                                    String newObject = at.GetObjectString(newUserForm);
                                    at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, "NA", newObject);

                                    return(Request.CreateResponse(HttpStatusCode.OK));
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "You cannot add new user form 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 form."));
                        }
                    }
                    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."));
            }
        }