示例#1
0
        public async Task SaveAsync(CategoryDto input)
        {
            var CategoryData = _mapper.Map <Category>(input);

            try
            {
                if (await _dbContext.Categories.AsNoTracking().SingleOrDefaultAsync(x => x.Id == input.Id)
                    == null !)
                {
                    // var Id= _user.GetUserId(_accessor.HttpContext.User);
                    var result = SaveAsyncUtility <Category> .UpdateDefaultFieldsForAddAndUpdate(CategoryData, input.UserId, false);

                    await _dbContext.AddAsync(result);

                    await _dbContext.SaveChangesAsync();
                }
                else
                {
                    var result = SaveAsyncUtility <Category> .UpdateDefaultFieldsForAddAndUpdate(CategoryData, input.UserId, true);

                    _dbContext.Categories.Update(result);
                    await _dbContext.SaveChangesAsync();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#2
0
        public ServiceResponse Delete(long id, long userId)
        {
            try
            {
                var productData = _context.ProductMaster.FirstOrDefault(x => x.Id == id);
                if (productData != null)
                {
                    productData.IsDelete = true;
                    var parentResult = SaveAsyncUtility <ProductMaster> .UpdateDefaultFieldsForAddAndUpdate(productData, userId, true);

                    _context.Update(productData);
                    _context.SaveChanges();
                    return(new ServiceResponse {
                        status = 1, isSuccess = true, message = "Product " + CommonMessages.DeleteStatus
                    });
                }
                else
                {
                    return(new ServiceResponse {
                        status = 1, isSuccess = true, message = CommonMessages.SomethingWrong
                    });
                }
            }
            catch (Exception)
            {
                return(new ServiceResponse {
                    status = 0, isSuccess = false, message = CommonMessages.SomethingWrong
                });
            }
        }
示例#3
0
        public async Task <bool> updateImage(string[] FileName, long UserId, long ProductId)
        {
            try {
                ProductImageDto imageDto = new ProductImageDto();

                string path = Path.Combine(FolderPath.webRootPath, FolderPath.ProductImage);
                foreach (var item in FileName)
                {
                    Byte[]     bytes            = Convert.FromBase64String(item.Split(',')[1]);
                    string     newFileName      = DateTime.Now.Ticks.ToString("HHmmss");
                    string     ogirinalFileName = RendomFileName(newFileName);
                    FileStream file             = File.Create(path + "\\" + ogirinalFileName);
                    await file.WriteAsync(bytes, 0, bytes.Length);

                    file.Close();
                    var ProductImageData = _mapper.Map <ProductsImages>(imageDto);

                    var imgRes = SaveAsyncUtility <ProductsImages> .UpdateDefaultFieldsForAddAndUpdate(ProductImageData, UserId, false);

                    imgRes.ImageName = ogirinalFileName;
                    imgRes.ProductId = ProductId;
                    await _context.AddAsync(imgRes);

                    await _context.SaveChangesAsync();
                }
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
示例#4
0
        public async Task SaveAsync(ProductDto input)
        {
            List <FileUploadDto> fileUploadDtos = new List <FileUploadDto>();
            var ProductData = _mapper.Map <ProductMaster>(input);

            try
            {
                if (input.Id == 0)
                {
                    if (await _context.ProductMaster.AsNoTracking().SingleOrDefaultAsync(x => x.Id == input.Id)
                        == null !)
                    {
                        #region product Insert
                        var result = SaveAsyncUtility <ProductMaster> .UpdateDefaultFieldsForAddAndUpdate(ProductData, input.UserId, false);

                        var res = await _context.AddAsync(result);

                        var insertResult = await _context.SaveChangesAsync();

                        #endregion

                        #region Product Image Insert
                        await updateImage(input.FileName, input.UserId, ProductData.Id);

                        #endregion
                    }
                }
                else
                {
                    var result = SaveAsyncUtility <ProductMaster> .UpdateDefaultFieldsForAddAndUpdate(ProductData, input.UserId, true);

                    _context.ProductMaster.Update(result);
                    await _context.SaveChangesAsync();

                    #region Product Image Update
                    var proImgData = _context.ProductsImage.Where(x => x.ProductId == ProductData.Id);
                    _context.ProductsImage.RemoveRange(proImgData);
                    _context.SaveChanges();

                    await updateImage(input.FileName, input.UserId, ProductData.Id);

                    #endregion
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
示例#5
0
        public ServiceResponse Delete(CommonDto input)
        {
            using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var parentCategory = _dbContext.Categories.FirstOrDefault(x => x.Id == input.Id);
                    parentCategory.IsDelete = true;
                    var parentResult = SaveAsyncUtility <Category> .UpdateDefaultFieldsForAddAndUpdate(parentCategory, input.UserId, true);

                    _dbContext.Update(parentResult);
                    _dbContext.SaveChanges();
                    var res = _dbContext.Categories.Where(x => x.ParentCategoryId == parentCategory.Id);
                    if (res.Count() != 0)
                    {
                        foreach (var item in res)
                        {
                            item.IsDelete = true;

                            var result = SaveAsyncUtility <Category> .UpdateDefaultFieldsForAddAndUpdate(item, input.UserId, true);

                            _dbContext.Update(result);
                            _dbContext.SaveChanges();
                        }
                    }
                    txscope.Complete();
                    return(new ServiceResponse {
                        status = 1, isSuccess = true, message = "Category " + CommonMessages.DeleteStatus
                    });
                }
                catch (Exception e)
                {
                    txscope.Dispose();
                    return(new ServiceResponse {
                        status = 0, isSuccess = false, message = e.Message
                    });
                }
            }
        }