Beispiel #1
0
        public HttpResponseMessage UpdateStockCountItem(Entities.TrnStockCountItem objStockCountItem, String id, String SCId)
        {
            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("StockCountDetail")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanEdit)
                        {
                            var stockIn = from d in db.TrnStockCounts
                                          where d.Id == Convert.ToInt32(SCId)
                                          select d;

                            if (stockIn.Any())
                            {
                                if (!stockIn.FirstOrDefault().IsLocked)
                                {
                                    var stockCountItem = from d in db.TrnStockCountItems
                                                         where d.Id == Convert.ToInt32(id)
                                                         select d;

                                    if (stockCountItem.Any())
                                    {
                                        var item = from d in db.MstArticles
                                                   where d.Id == objStockCountItem.ItemId &&
                                                   d.ArticleTypeId == 1 &&
                                                   d.IsLocked == true
                                                   select d;

                                        if (item.Any())
                                        {
                                            var conversionUnit = from d in db.MstArticleUnits
                                                                 where d.ArticleId == objStockCountItem.ItemId &&
                                                                 d.UnitId == objStockCountItem.UnitId &&
                                                                 d.MstArticle.IsLocked == true
                                                                 select d;

                                            if (conversionUnit.Any())
                                            {
                                                var updateStockCountItem = stockCountItem.FirstOrDefault();
                                                updateStockCountItem.SCId        = Convert.ToInt32(SCId);
                                                updateStockCountItem.ItemId      = objStockCountItem.ItemId;
                                                updateStockCountItem.Particulars = objStockCountItem.Particulars;
                                                updateStockCountItem.Quantity    = objStockCountItem.Quantity;
                                                db.SubmitChanges();

                                                return(Request.CreateResponse(HttpStatusCode.OK));
                                            }
                                            else
                                            {
                                                return(Request.CreateResponse(HttpStatusCode.BadRequest, "The selected item has no unit conversion."));
                                            }
                                        }
                                        else
                                        {
                                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "The selected item was not found in the server."));
                                        }
                                    }
                                    else
                                    {
                                        return(Request.CreateResponse(HttpStatusCode.NotFound, "This stock count item detail is no longer exist in the server."));
                                    }
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "You cannot update stock count item if the current stock count detail is locked."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "These current stock count details are not found in the server. Please add new stock count first before proceeding."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to edit and update stock count item in this stock count detail page."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access in this stock count detail 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."));
            }
        }
        public HttpResponseMessage AddStockCountItem(Entities.TrnStockCountItem objStockCountItem, String SCId)
        {
            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("StockCountDetail")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            var stockIn = from d in db.TrnStockCounts
                                          where d.Id == Convert.ToInt32(SCId)
                                          select d;

                            if (stockIn.Any())
                            {
                                if (!stockIn.FirstOrDefault().IsLocked)
                                {
                                    var item = from d in db.MstArticles
                                               where d.Id == objStockCountItem.ItemId &&
                                               d.ArticleTypeId == 1 &&
                                               d.IsLocked == true
                                               select d;

                                    if (item.Any())
                                    {
                                        var conversionUnit = from d in db.MstArticleUnits
                                                             where d.ArticleId == objStockCountItem.ItemId &&
                                                             d.UnitId == objStockCountItem.UnitId &&
                                                             d.MstArticle.IsLocked == true
                                                             select d;

                                        if (conversionUnit.Any())
                                        {
                                            Data.TrnStockCountItem newStockCountItem = new Data.TrnStockCountItem
                                            {
                                                SCId        = Convert.ToInt32(SCId),
                                                ItemId      = objStockCountItem.ItemId,
                                                Particulars = objStockCountItem.Particulars,
                                                Quantity    = objStockCountItem.Quantity
                                            };

                                            db.TrnStockCountItems.InsertOnSubmit(newStockCountItem);
                                            db.SubmitChanges();

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

                                            return(Request.CreateResponse(HttpStatusCode.OK));
                                        }
                                        else
                                        {
                                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "The selected item has no unit conversion."));
                                        }
                                    }
                                    else
                                    {
                                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "The selected item was not found in the server."));
                                    }
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "You cannot add new stock count item if the current stock count detail is locked."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "These current stock count details are not found in the server. Please add new stock count first before proceeding."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add new stock count item in this stock count detail page."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access in this stock count detail 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."));
            }
        }