Esempio n. 1
0
        private static ResultModel <string> _validationInvoice(InvoiceModel param)
        {
            end.StatusCode = (int)HttpStatusCode.NotAcceptable;
            if (param == null)
            {
                end.StatusMessage = "Parameter is empty";
                return(end);
            }
            if (string.IsNullOrEmpty(param.ID))
            {
                end.StatusMessage = "No Invoice is required";
                return(end);
            }
            if (!param.TransactionDate.HasValue)
            {
                end.StatusMessage = "Transaction Date is required";
                return(end);
            }
            if (!param.UsersID.HasValue)
            {
                end.StatusMessage = "Customer is required";
                return(end);
            }
            if (param.Items.Count < 1)
            {
                end.StatusMessage = "List Product is required";
                return(end);
            }
            var user = ManageUser.GetById(param.UsersID.Value);

            if (user == null)
            {
                end.StatusMessage = "Customer is not found";
                return(end);
            }
            var No = ManageInvoice.GetById(param.ID);

            if (No != null)
            {
                param.ID = GenerateInvoice().Value;
            }
            foreach (ListInvoiceModel item in param.Items)
            {
                var Product = ManageCatalogue.GetById(item.CatalogueID);
                if (Product == null)
                {
                    end.StatusMessage = "Product is not found";
                    return(end);
                }
                if (Product.Qty < item.Qty)
                {
                    end.StatusMessage = "Quantity Product smaller than Request";
                    return(end);
                }
            }
            end.StatusCode = (int)HttpStatusCode.OK;
            return(end);
        }
Esempio n. 2
0
        public ResultModel <List <Catalogue> > GetAll()
        {
            ResultModel <List <Catalogue> > res = new ResultModel <List <Catalogue> >();

            var ret = ManageCatalogue.GetAll().Where(x => x.Qty > 1).ToList();

            res.StatusCode = (int)HttpStatusCode.NotFound;
            if (ret != null && ret.Count >= 1)
            {
                res.StatusCode = (int)HttpStatusCode.OK; res.Value = ret;
            }
            return(res);
        }
Esempio n. 3
0
        public ResultModel <Catalogue> GetById(int id)
        {
            ResultModel <Catalogue> res = new ResultModel <Catalogue>();

            var ret = ManageCatalogue.GetById(id);

            res.StatusCode = (int)HttpStatusCode.NotFound;
            if (ret != null)
            {
                res.StatusCode = (int)HttpStatusCode.OK; res.Value = ret;
            }
            return(res);
        }
Esempio n. 4
0
        public ResultModel <List <Catalogue> > GetByNameOrCode(string param)
        {
            ResultModel <List <Catalogue> > res = new ResultModel <List <Catalogue> >();

            var ret = ManageCatalogue.GetAll()
                      .Where(x => x.Name.Contains(param) || x.Code.Contains(param)).ToList();

            res.StatusCode = (int)HttpStatusCode.NotFound;
            if (ret != null)
            {
                res.StatusCode = (int)HttpStatusCode.OK; res.Value = ret;
            }
            return(res);
        }
Esempio n. 5
0
        public static ResultModel <EFResponse> UpdateCatalogue(Catalogue param)
        {
            res.StatusCode = (int)HttpStatusCode.NotFound;
            var User = ManageCatalogue.GetById(param.ID);

            if (User != null)
            {
                res.StatusCode = (int)HttpStatusCode.Found;
                var ret = ManageCatalogue.Update(param);
                if (ret.Success)
                {
                    res.StatusCode = (int)HttpStatusCode.OK; res.Value = ret;
                }
            }
            return(res);
        }
Esempio n. 6
0
        public static ResultModel <EFResponse> InsertInvoice(InvoiceModel param)
        {
            var validate = _validationInvoice(param);

            if (validate.StatusCode != (int)HttpStatusCode.OK)
            {
                res.StatusCode    = validate.StatusCode;
                res.StatusMessage = validate.StatusMessage;
                return(res);
            }

            res.StatusCode = (int)HttpStatusCode.OK;
            long Total = 0;

            Invoice Receipt = new Invoice();

            Receipt.ID = param.ID;
            Receipt.TransactionDate = param.TransactionDate;
            Receipt.UsersID         = param.UsersID;

            foreach (ListInvoiceModel item in param.Items)
            {
                var product = ManageCatalogue.GetById(item.CatalogueID);
                #region To List Invoice
                Total = Total + (product.Price.Value * item.Qty);
                ListInvoice collect = new ListInvoice();
                collect.InovicesID  = Receipt.ID;
                collect.CatalogueID = item.CatalogueID;
                collect.Qty         = item.Qty;
                collect.Price       = product.Price;
                collect.SumPrice    = (product.Price * item.Qty);
                ManageListInvoice.Insert(collect);
                #endregion

                product.Qty = Convert.ToInt16(product.Qty - item.Qty);
                UpdateCatalogue(product);
            }

            Receipt.TotalPrice = Total;
            var ret = ManageInvoice.Insert(Receipt);

            return(res);
        }
Esempio n. 7
0
        public static ResultModel <EFResponse> InsertCatalogue(Catalogue param)
        {
            var validate = _validationCatalogue(param);

            if (validate.StatusCode != (int)HttpStatusCode.OK)
            {
                res.StatusCode    = validate.StatusCode;
                res.StatusMessage = validate.StatusMessage;
                return(res);
            }
            var ret = ManageCatalogue.Insert(param);

            res.StatusCode = (int)HttpStatusCode.ExpectationFailed;
            if (ret.Success)
            {
                res.StatusCode = (int)HttpStatusCode.OK; res.Value = ret;
            }
            return(res);
        }
Esempio n. 8
0
        private static ResultModel <string> _validationCatalogue(Catalogue param)
        {
            end.StatusCode = (int)HttpStatusCode.NotAcceptable;
            if (param == null)
            {
                end.StatusMessage = "Parameter is empty";
                return(end);
            }
            if (string.IsNullOrEmpty(param.Code))
            {
                end.StatusMessage = "No Invoice is required";
                return(end);
            }
            if (!param.Qty.HasValue)
            {
                end.StatusMessage = "Transaction Date is required";
                return(end);
            }
            if (!param.Price.HasValue)
            {
                end.StatusMessage = "Customer is required";
                return(end);
            }
            if (param.Price < 1 || param.Qty < 1)
            {
                end.StatusMessage = "Oops...!! Price or Quantity add more";
                return(end);
            }
            var catalog = ManageCatalogue.GetAll().FirstOrDefault(x => x.Code == param.Code);

            if (catalog != null)
            {
                end.StatusMessage = "Code is used";
                return(end);
            }
            end.StatusCode = (int)HttpStatusCode.OK;
            return(end);
        }