Exemplo n.º 1
0
        public async Task <BaseModel> Insert(Ref_StockModel stock)
        {
            Ref_Stock stockToDB = new Ref_Stock();

            stockToDB.stockID      = stock.stockID;
            stockToDB.code         = stock.code;
            stockToDB.title        = stock.title;
            stockToDB.description  = stock.description;
            stockToDB.mainImageURL = stock.mainImageURL;
            stockToDB.colorCode    = stock.colorCode;
            stockToDB.userID       = stock.userID;

            try
            {
                string convertedImageData = stock.imageData.Substring(stock.imageData.LastIndexOf(',') + 1);
                byte[] image64            = Convert.FromBase64String(convertedImageData);

                SettingsService settings  = new SettingsService(_adminConnectionString, _sCConnectionString);
                string          imagePath = settings.SelectWithinProject("IMGP").Value;

                string filePath = imagePath + "\\Stock\\" + stockToDB.code + "\\Main.jpg";
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                    File.WriteAllBytes(filePath, image64);
                }
                else
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                    File.WriteAllBytes(filePath, image64);
                }


                stockToDB.mainImageURL = filePath;

                using (var connection = new SqlConnection(_sCConnectionString))
                {
                    DynamicParameters para     = new DynamicParameters();
                    string            JsonData = JsonConvert.SerializeObject(stockToDB);
                    para.Add("@JsonData", JsonData, DbType.String);
                    para.Add("@Action", "I", DbType.String);

                    await connection.ExecuteAsync("[dbo].[TAG_AD_POPULATE_Stocks]", para, commandType : System.Data.CommandType.StoredProcedure);

                    return(new BaseModel()
                    {
                        code = "1000", description = "Success", data = stockToDB
                    });
                }
            }
            catch (Exception ex)
            {
                return(new BaseModel()
                {
                    code = "998", description = ex.Message, data = stockToDB
                });
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Delete(Ref_StockModel data)
        {
            var response = await _service.Delete(data);

            return(Ok(response));
        }