コード例 #1
0
 public void UpdateInventoryItem(InventoryItems item)
 {
     _services.UpdateInventoryItem(item);
 }
コード例 #2
0
        public async Task <ActionResult <InventoryItems> > PostAsync(Dictionary <string, object> items)
        {
            Dictionary <string, string> msg;

            var check = new ParameterInput();

            if (!string.IsNullOrWhiteSpace(items["Version"].ToString()) &&
                items["Version"].ToString().Trim().Length != 0)
            {
                if (check.isValidVersion(items["Version"].ToString()) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Version incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Version can't empty." }
                };
                return(BadRequest(msg));
            }

            if (!string.IsNullOrWhiteSpace(items["Start_Date"].ToString()) &&
                items["Start_Date"].ToString().Trim().Length != 0)
            {
                DateTime myDateTime = DateTime.SpecifyKind(
                    DateTime.Parse(items["Start_Date"].ToString()),
                    DateTimeKind.Utc);
                string a = myDateTime.ToString("o");

                if (check.isValidStart_Date(a) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Start date incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Start date can't empty." }
                };
                return(BadRequest(msg));
            }

            if (!string.IsNullOrWhiteSpace(items["End_Date"].ToString()) &&
                items["End_Date"].ToString().Trim().Length != 0)
            {
                DateTime myDateTime = DateTime.SpecifyKind(
                    DateTime.Parse(items["End_Date"].ToString()),
                    DateTimeKind.Utc);
                string a = myDateTime.ToString("o");

                if (check.isValidEnd_Date(a) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "End date incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "End date can't empty." }
                };
                return(BadRequest(msg));
            }

            if (!string.IsNullOrWhiteSpace(items["Display_Name"].ToString()) &&
                items["Display_Name"].ToString().Trim().Length != 0)
            {
                if (check.isValidDisplay_Name(items["Display_Name"].ToString()) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Display name incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Display name can't empty." }
                };
                return(BadRequest(msg));
            }

            if (!string.IsNullOrWhiteSpace(items["Description"].ToString()) &&
                items["Description"].ToString().Trim().Length != 0)
            {
                if (check.isValidDescription(items["Description"].ToString()) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Description incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Description can't empty." }
                };
                return(BadRequest(msg));
            }

            if (!string.IsNullOrWhiteSpace(items["Catalog_Ref_Id"].ToString()))
            {
                if (items["Catalog_Ref_Id"].ToString().Trim().Length != 24)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Catalog ref id length is 24" }
                    };
                    return(BadRequest(msg));
                }
                if (check.isValidCatalog_Ref_Id(items["Catalog_Ref_Id"].ToString()) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Catalog ref id incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Catalog ref id can't empty." }
                };
                return(BadRequest(msg));
            }


            if (!string.IsNullOrWhiteSpace(items["Availability_Status"].ToString()) &&
                items["Availability_Status"].ToString().Trim().Length != 0)
            {
                if (check.isValidAvailability_Status(items["Availability_Status"].ToString()) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Availability status incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Availability status can't empty." }
                };
                return(BadRequest(msg));
            }


            if (!string.IsNullOrWhiteSpace(items["Availability_Date"].ToString()) &&
                items["Availability_Date"].ToString().Trim().Length != 0)
            {
                DateTime myDateTime = DateTime.SpecifyKind(
                    DateTime.Parse(items["Availability_Date"].ToString()),
                    DateTimeKind.Utc);
                string a = myDateTime.ToString("o");

                if (check.isValidAvailability_Date(a) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Availability date incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Availability date can't empty." }
                };
                return(BadRequest(msg));
            }

            if (!string.IsNullOrWhiteSpace(items["Stock_Level"].ToString()) &&
                items["Stock_Level"].ToString().Trim().Length != 0)
            {
                if (check.isValidStock_Level(items["Stock_Level"].ToString()) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Stock level incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Stock level can't empty." }
                };
                return(BadRequest(msg));
            }

            if (!string.IsNullOrWhiteSpace(items["Stock_Thresh"].ToString()) &&
                items["Stock_Thresh"].ToString().Trim().Length != 0)
            {
                if (check.isValidStock_Thresh(items["Stock_Thresh"].ToString()) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Stock Thresh inccorect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Stock Thres can't empty." }
                };
                return(BadRequest(msg));
            }

            if (!string.IsNullOrWhiteSpace(items["Product_Id"].ToString()))
            {
                if (items["Product_Id"].ToString().Trim().Length != 24)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Product id length is 24" }
                    };
                    return(BadRequest(msg));
                }

                if (check.isValidProduct_Id(items["Product_Id"].ToString()) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Product id incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Product id can't empty." }
                };
                return(BadRequest(msg));
            }

            if (!string.IsNullOrWhiteSpace(items["Created_By"].ToString()))
            {
                if (items["Created_By"].ToString().Trim().Length != 24)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Created by id length is 24" }
                    };
                    return(BadRequest(msg));
                }

                if (check.isValidCreated_By(items["Created_By"].ToString()) != true)
                {
                    msg = new Dictionary <string, string>()
                    {
                        { "msg", "Created by incorrect." }
                    };
                    return(BadRequest(msg));
                }
            }
            else
            {
                msg = new Dictionary <string, string>()
                {
                    { "msg", "Created by can't empty." }
                };
                return(BadRequest(msg));
            }

            InventoryItems item = new InventoryItems(
                int.Parse(items["Version"].ToString()),
                DateTime.Parse(items["Start_Date"].ToString()),
                DateTime.Parse(items["End_Date"].ToString()),
                items["Display_Name"].ToString(),
                items["Description"].ToString(),
                items["Catalog_Ref_Id"].ToString(),
                items["Availability_Status"].ToString(),
                DateTime.Parse(items["Availability_Date"].ToString()),
                int.Parse(items["Stock_Level"].ToString()),
                int.Parse(items["Stock_Thresh"].ToString()),
                items["Product_Id"].ToString(),
                items["Created_By"].ToString()
                );


            var inventoryItems = _services.AddInventoryItemsAsync(item);

            if (inventoryItems == null)
            {
                return(NotFound());
            }

            return(await inventoryItems);
        }