Exemplo n.º 1
0
 public IActionResult AddCampaign([FromForm] AddUpdateCampaignModel addCampaignModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var productCategoryTypeModel = iProductCategoryType.ProductCategoryTypeDetail(DBHelper.ParseInt64(addCampaignModel.CampaignId));
             var hostingPath = env.ContentRootPath;
             ProductCategoryType productCategoryType = ProductCategoryTypeHelper.BindProductCategoryTypeModel(addCampaignModel, hostingPath, productCategoryTypeModel);
             if (addCampaignModel.CampaignId <= 0)
             {
                 long productCategoryTypeId = iProductCategoryType.AddNewProductCategoryType(productCategoryType, addCampaignModel.ProductId);
                 if (productCategoryTypeId > 0)
                 {
                     return(Ok(ResponseHelper.Success(MessageConstants.CampaignAdded)));
                 }
                 else if (productCategoryTypeId == ReturnCode.AlreadyExist.GetHashCode())
                 {
                     ProductCategoryTypeHelper.DeleteProductImageToFolder(productCategoryType.Image, hostingPath);
                     return(Ok(ResponseHelper.Error(MessageConstants.CampaignExists)));
                 }
                 else
                 {
                     ProductCategoryTypeHelper.DeleteProductImageToFolder(productCategoryType.Image, hostingPath);
                     return(Ok(ResponseHelper.Error(MessageConstants.CampaignNotAdded)));
                 }
             }
             else
             {
                 long productCategoryTypeId = iProductCategoryType.UpdateProductCategoryType(productCategoryType, DBHelper.ParseInt64(productCategoryType.UpdatedBy), addCampaignModel.ProductId);
                 if (productCategoryTypeId > 0)
                 {
                     return(Ok(ResponseHelper.Success(MessageConstants.CampaignUpdated)));
                 }
                 else if (productCategoryTypeId == ReturnCode.AlreadyExist.GetHashCode())
                 {
                     ProductCategoryTypeHelper.DeleteProductImageToFolder(productCategoryType.Image, hostingPath);
                     return(Ok(ResponseHelper.Error(MessageConstants.CampaignExists)));
                 }
                 else
                 {
                     ProductCategoryTypeHelper.DeleteProductImageToFolder(productCategoryType.Image, hostingPath);
                     return(Ok(ResponseHelper.Error(MessageConstants.CampaignNotUpdated)));
                 }
             }
         }
         else
         {
             return(Ok(ResponseHelper.Error(MessageConstants.CompulsoryData)));
         }
     }
     catch (Exception ex)
     {
         LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
         return(Ok(ResponseHelper.Error(ex.Message)));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Binds the product category type model.
        /// </summary>
        /// <param name="addProductCategoryTypeModel">The add product category type model.</param>
        /// <param name="hostPath">The host path.</param>
        /// <returns></returns>
        public static ProductCategoryType BindProductCategoryTypeModel(AddUpdateCampaignModel addProductCategoryTypeModel, string hostPath, ProductCategoryType productCategoryType)
        {
            ProductCategoryType productCategoryTypeModel = new ProductCategoryType();

            if (addProductCategoryTypeModel != null)
            {
                if (DBHelper.ParseInt64(addProductCategoryTypeModel.CampaignId) <= 0)
                {
                    productCategoryTypeModel.CreatedBy = DBHelper.ParseInt64(addProductCategoryTypeModel.UpdatedBy);
                    productCategoryTypeModel.CreatedOn = DateTime.Now;
                    productCategoryTypeModel.Image     = SaveProductCategoryTypeImageToFolder(addProductCategoryTypeModel.Image, hostPath);
                }
                else
                {
                    productCategoryTypeModel.ProductCategoryTypeId = DBHelper.ParseInt64(addProductCategoryTypeModel.CampaignId);
                    productCategoryTypeModel.UpdatedBy             = DBHelper.ParseInt64(addProductCategoryTypeModel.UpdatedBy);
                    productCategoryTypeModel.ModifiedOn            = DateTime.Now;
                    if (addProductCategoryTypeModel.IsImageDeleted)
                    {
                        DeleteProductImageToFolder(productCategoryType.Image, hostPath);
                        productCategoryTypeModel.Image = string.Empty;
                    }
                    else if (addProductCategoryTypeModel.Image == null)
                    {
                        productCategoryTypeModel.Image = productCategoryType.Image;
                    }
                    else
                    {
                        productCategoryTypeModel.Image = SaveProductCategoryTypeImageToFolder(addProductCategoryTypeModel.Image, hostPath);
                    }
                }
                productCategoryTypeModel.CategoryType      = addProductCategoryTypeModel.CampaignName;
                productCategoryTypeModel.ProductCategoryFK = ProductCategoryEnum.Campaign.GetHashCode();
                productCategoryTypeModel.Description       = addProductCategoryTypeModel.Description;
                productCategoryTypeModel.IsShowInFrontend  = addProductCategoryTypeModel.IsShowinFrontend;
            }
            return(productCategoryTypeModel);
        }