private void AddAlternatingRows() { var firstColor = new Color() { Alpha = 1, Red = 1, Green = 1, Blue = 1, }; var secondColor = new Color() { Alpha = 1, Red = (float)0xe8 / 256, Green = (float)0xe7 / 256, Blue = (float)0xfc / 256, }; foreach (var category in _budget.Categories) { var subcategoriesInCategory = _budget.Subcategories.Where(x => x.CategoryId == category.Id); SubcategoryDto firstSubcategory = subcategoriesInCategory.FirstOrDefault(); SubcategoryDto lastsSubcategory = subcategoriesInCategory.LastOrDefault(); int firstRow = _subcategoryRows.FirstOrDefault(x => x.Id == firstSubcategory.Id)?.RowIndex ?? 0; int lastRow = _subcategoryRows.FirstOrDefault(x => x.Id == lastsSubcategory.Id)?.RowIndex + 1 ?? 1; _googleSheetService.AddBandedRange(0, 4, firstRow, lastRow, firstColor, secondColor); } }
public IActionResult PutSubcategory(int id, [FromBody] SubcategoryDto subcategory) { try { _subcategoryService.UpdateSubcategory(id, subcategory); return(Ok()); } catch (Exception ex) { } return(BadRequest("")); }
public IActionResult PostSubcategory([FromBody] SubcategoryDto subcategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _subcategoryService.PostSubcategory(subcategory); return(Ok()); } catch (Exception err) { } return(BadRequest()); }
public async Task <MainCategoryDto> CreateSubcategoryAsync(int userId, int parentCategoryId, SubcategoryDto subcategoryDto) { var categories = GetUserCategories(userId).ToList(); ThrowIfParentNotContains(categories, parentCategoryId); ThrowIfCategorySameName(categories, subcategoryDto.Name); var parentCategory = categories.Single(x => x.CategoryId == parentCategoryId); var subcategoryEntity = Mapper.Map <Subcategory>(subcategoryDto); parentCategory.Subcategories.Add(subcategoryEntity); UnitOfWork.CategoryRepository.Update(parentCategory); await UnitOfWork.CommitAsync(); return(Mapper.Map <MainCategoryDto>(parentCategory)); }
public static string GetSubCategoryName(int?subcatId, List <CategoryDto> categoryTree) { if (subcatId == null || categoryTree == null || !categoryTree.Any()) { return(null); } // var result = categoryTree.Select(e => e.Subcategories.FirstOrDefault(t => t.SubcategoryId == subcatId)).FirstOrDefault(); SubcategoryDto result = null; foreach (CategoryDto cat in categoryTree) { if (cat.Subcategories == null || cat.Subcategories.All(d => d.SubcategoryId != subcatId)) { continue; } result = cat.Subcategories.First(r => r.SubcategoryId == subcatId); } return(result == null ? null : result.Subcategory); }
public async Task <IActionResult> UpdateSubcategory(int id, [FromBody] SubcategoryDto subcategoryDto) { return(await Do(async() => await _categoryService.UpdateSubcategory(id, subcategoryDto.CategoryId, subcategoryDto.Name))); }
public async Task <IActionResult> AddSubcategory([FromBody] SubcategoryDto subcategoryDto) { return(await Create(nameof(GetSubcategoriesForAdmin), async() => await _categoryService.AddSubcategory(subcategoryDto.CategoryId, subcategoryDto.Name))); }
public void UpdateSubcategory(int id, SubcategoryDto subcategory) { var sub = _mapper.Map <ChallengeSubcategories>(subcategory); _subcategoryRepository.UpdateSubcategory(id, sub); }
public void PostSubcategory(SubcategoryDto item) { var sub = _mapper.Map <ChallengeSubcategories>(item); _subcategoryRepository.PostSubcategory(sub); }
public bool AddSubcategories(SubcategoryDto dataDto) { if (dataDto != null) { using (EcommerceDB context = new EcommerceDB()) { if (dataDto.Id <= 0) { Subcategory AddData = new Subcategory(); AddData.Name = dataDto.Name; if (dataDto.Image != null && dataDto.Image != "" && AddData.Image != dataDto.Image && !dataDto.Image.Contains("http")) { Guid id = Guid.NewGuid(); var imgData = dataDto.Image.Substring(dataDto.Image.IndexOf(",") + 1); byte[] bytes = Convert.FromBase64String(imgData); Image image; using (MemoryStream ms = new MemoryStream(bytes)) { image = Image.FromStream(ms); } Bitmap b = new Bitmap(image); string filePath = System.Web.HttpContext.Current.Server.MapPath("~") + "UploadedFiles\\" + id + ".jpg"; b.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg); AddData.Image = string.Concat("UploadedFiles\\" + id + ".jpg"); } AddData.CategoryId = dataDto.CategoryId; AddData.IsActive = true; context.Subcategories.Add(AddData); context.SaveChanges(); return(true); } else { var olddata = context.Subcategories.FirstOrDefault(x => x.Id == dataDto.Id); if (olddata != null) { olddata.Name = dataDto.Name; if (dataDto.Image != null && dataDto.Image != "" && olddata.Image != dataDto.Image && !dataDto.Image.Contains("http")) { Guid id = Guid.NewGuid(); var imgData = dataDto.Image.Substring(dataDto.Image.IndexOf(",") + 1); byte[] bytes = Convert.FromBase64String(imgData); Image image; using (MemoryStream ms = new MemoryStream(bytes)) { image = Image.FromStream(ms); } Bitmap b = new Bitmap(image); string filePath = System.Web.HttpContext.Current.Server.MapPath("~") + "UploadedFiles\\" + id + ".jpg"; b.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg); olddata.Image = string.Concat("UploadedFiles\\" + id + ".jpg"); context.Entry(olddata).Property(x => x.Image).IsModified = true; } olddata.IsActive = true; olddata.CategoryId = dataDto.CategoryId; context.Entry(olddata).Property(x => x.CategoryId).IsModified = true; context.Entry(olddata).Property(x => x.IsActive).IsModified = true; olddata.IsActive = true; context.SaveChanges(); return(true); } } } } return(false); }