Example #1
0
        public HttpResponseMessage AddItemCategory(Entities.MstArticleCategory objItemCategory)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var userForms = from d in db.MstUserForms
                                    where d.UserId == currentUser.FirstOrDefault().Id &&
                                    d.SysForm.FormName.Equals("SystemTables")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            Data.MstArticleCategory newItemCategory = new Data.MstArticleCategory
                            {
                                Category         = objItemCategory.Category,
                                CategoryImageURL = objItemCategory.CategoryImageURL,
                                IsLocked         = true,
                                CreatedById      = currentUser.FirstOrDefault().Id,
                                CreatedDateTime  = DateTime.Now,
                                UpdatedById      = currentUser.FirstOrDefault().Id,
                                UpdatedDateTime  = DateTime.Now
                            };

                            db.MstArticleCategories.InsertOnSubmit(newItemCategory);
                            db.SubmitChanges();

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

                            return(Request.CreateResponse(HttpStatusCode.OK, newItemCategory.Id));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add item category."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this system table 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."));
            }
        }
Example #2
0
        public HttpResponseMessage UpdateArcticleCategory(Entities.MstArticleCategory objItemCategory, String id)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var userForms = from d in db.MstUserForms
                                    where d.UserId == currentUser.FirstOrDefault().Id &&
                                    d.SysForm.FormName.Equals("SystemTables")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanEdit)
                        {
                            var articleCategories = from d in db.MstArticleCategories
                                                    where d.Id == Convert.ToInt32(id)
                                                    select d;

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

                                var updateItemCategory = articleCategories.FirstOrDefault();
                                updateItemCategory.Category         = objItemCategory.Category;
                                updateItemCategory.CategoryImageURL = objItemCategory.CategoryImageURL;
                                updateItemCategory.IsLocked         = true;
                                updateItemCategory.UpdatedById      = currentUser.FirstOrDefault().Id;
                                updateItemCategory.UpdatedDateTime  = DateTime.Now;
                                db.SubmitChanges();

                                String newObject = at.GetObjectString(articleCategories.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 article category details are not found in the server."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to edit and update article category."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this system table 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."));
            }
        }