Beispiel #1
0
        //to insert
        public async Task <BaseModel> Insert(Ref_RetailModel retail)
        {
            Ref_Retail retailToDB = new Ref_Retail();

            retailToDB.retailID             = retail.retailID;
            retailToDB.code                 = retail.code;
            retailToDB.title                = retail.title;
            retailToDB.description          = retail.description;
            retailToDB.mainImageURL         = retail.mainImageURL;
            retailToDB.colorCode            = retail.colorCode;
            retailToDB.userID               = retail.userID;
            retailToDB.commissionPercentage = retail.commissionPercentage;
            retailToDB.isActive             = retail.isActive;

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

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

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


                retailToDB.mainImageURL = filePath;

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

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

                    return(new BaseModel()
                    {
                        code = "1000", description = "Success", data = retailToDB
                    });
                }
            }
            catch (Exception ex)
            {
                return(new BaseModel()
                {
                    code = "998", description = ex.Message, data = retailToDB
                });
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Delete(Ref_RetailModel data)
        {
            var response = await _service.Delete(data);

            return(Ok(response));
        }