public void Init(MainWindow main, UserCfg cfg) { _Main = main; _Cfg = cfg; MyView.ItemsSource = _Docs; //MyView.SetBinding(ItemsControl.ItemsSourceProperty, _Docs); BindingOperations.EnableCollectionSynchronization(_Docs, _LockObj); var path = Path.Combine(cfg.RootDir, "img"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } _RootCat = new CatImgDto(); _RootCat.names = "我的照片"; _RootCat.path = path; _RootCat.id = CatDto.TYPE_60_CODE; _RootCat.Init(cfg); _CurrCat = _RootCat; MyCat.ItemsSource = _RootCat.CatList; }
public async Task <bool> Save(CatDto dto) { if (dto == null) { return(false); } Cat model = await _context.Cats.FindAsync(dto.Id); bool isNew = model == null; model = ToModel(dto, model); if (isNew) { _context.Cats.Add(model); } else { _context.Cats.Update(model); } await _context.SaveChangesAsync(); return(true); }
//[Authorize] public async Task <ActionResult <Cat> > PostCat([FromBody] CatDto cat) { try { foreach (Image i in cat.Images) { _db.Images.Add(i); await _db.SaveChangesAsync(); } Cat newCat = cat; for (int i = 0; i < cat.Images.Count; i++) { newCat.Images.Add(new Cat_Image(cat.Id, cat.Images[i].Id)); } _db.Cats.Add(newCat); await _db.SaveChangesAsync(); return(Ok(newCat)); } catch (Exception e) { return(BadRequest(e)); } //return CreatedAtAction(nameof(GetAllCats), new { id = cat.Id }, cat); }
public string Post([FromBody] CatDto cat) { var domainCat = cat.Map(); _catService.Insert(domainCat); return("Inserted"); }
public void ProcessCat(CatDto cat) { var catDb = new Cat() { Color = cat.Color, Name = cat.Name }; Console.WriteLine($"{catDb.Name} is {catDb.Color}"); }
public async Task <IActionResult> EditCaseCategory(CatDto editCaseCategory) { if (ModelState.IsValid) { await _service.UpdateCaseCategory(editCaseCategory); return(RedirectToAction("GetAllCaseList")); } return(View()); }
public async Task <IActionResult> AddCaseCategory(CatDto addCaseCategory) { if (ModelState.IsValid) { var result = await _service.AddCaseCategory(addCaseCategory); if (result == false) { TempData["name"] = addCaseCategory.Name; } return(RedirectToAction("GetAllCaseList")); } return(View()); }
public void Should_match_same_name_properties() { var entity = new Cat() { Age = 15, Id = 8, Name = "Rex" }; var expected = new CatDto() { Age = 15, Id = 8, Name = "Rex" }; var actual = Translator.Translate <Cat, CatDto>(entity); Assert.That(actual, Is.EqualTo(expected)); }
public async Task <IActionResult> GetAllCaseList() { CatDto catDto = new CatDto(); catDto.CaseCategories = _service.GetAllCaseCategory(); catDto.CaseCategoryList = await _service.GetAllNonRecursive(); if (TempData["name"] != null) { var name = TempData["name"]; string Name = Convert.ToString(name); ModelState.AddModelError(string.Empty, Name + " Category already exist"); } return(View(catDto)); }
private CatDto ToDto(Cat model) { CatDto dto = new CatDto(); if (model == null) { return(dto); } dto.Id = model.Id; dto.PictureUrl = model.PictureUrl; dto.VoteDown = model.VoteDown; dto.VoteUp = model.VoteUp; return(dto); }
private string UploadedFile(CatDto addCaseCategory) { string uniqueFileName = null; if (addCaseCategory.Image != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "VectorIconImages"); uniqueFileName = Guid.NewGuid().ToString() + "_" + addCaseCategory.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { addCaseCategory.Image.CopyTo(fileStream); } } return(uniqueFileName); }
public async Task <ActionResult> EditCaseCategory(int id) { CatDto catDto = new CatDto(); var catlist = await _service.CatGetById(id); //ViewBag.CatList =new SelectList(await _service.GetAllNonRecursive(), "CaseCategoryId", "Name"); catDto.CaseCategoryList = await _service.GetAllNonRecursive(); catDto.CaseCategoryId = catlist.CaseCategoryId; catDto.Name = catlist.Name; catDto.Description = catlist.Description; catDto.ParentId = catlist.ParentId; catDto.VectorIcon = catlist.VectorIcon; return(View(catDto)); }
public async Task UpdateCaseCategory(CatDto editCaseCategory) { string uniqueFileName = UploadedFile(editCaseCategory); var caseCategory = await _context.CaseCategories.FindAsync(editCaseCategory.CaseCategoryId); caseCategory.Name = editCaseCategory.Name; caseCategory.ParentId = editCaseCategory.ParentId; caseCategory.Description = editCaseCategory.Description; if (uniqueFileName != null) { caseCategory.VectorIcon = uniqueFileName; } _context.Update(caseCategory); await _context.SaveChangesAsync(); }
private Cat ToModel(CatDto dto, Cat model) { if (model == null) { model = new Cat(); } if (dto == null) { return(null); } model.PictureUrl = dto.PictureUrl; model.VoteDown = dto.VoteDown; model.VoteUp = dto.VoteUp; return(model); }
public async Task <bool> AddCaseCategory(CatDto addCaseCategory) { var result = await _context.CaseCategories.Where(x => x.Name.Equals(addCaseCategory.Name)).ToListAsync(); if (result.Count == 0) { string uniqueFileName = UploadedFile(addCaseCategory); CaseCategory caseCategory = new CaseCategory { Name = addCaseCategory.Name, Description = addCaseCategory.Description, ParentId = addCaseCategory.ParentId, VectorIcon = uniqueFileName }; await _context.CaseCategories.AddAsync(caseCategory); await _context.SaveChangesAsync(); return(true); } return(false); }
public async Task <CatDto> GetCatClient(Guid clientId) { var order = await _orderRepository.GetDraftOrderByClientId(clientId); if (order == null) { return(null); } var cat = CatDto.Create(order.ClientId, order.TotalValue, order.Id, order.Discount, order.Discount + order.TotalValue); if (order.VoucherId != null) { cat.VoucherCode = order.Voucher.Code; } foreach (var item in order.OrderItems) { cat.Items.Add(CatItemsDto.Create(item.ProductId, item.NameProduct, item.Quantity, item.UnitValue, item.UnitValue * item.Quantity)); } return(cat); }
public static Cat Map(this CatDto cat) { return(new Cat(cat.Id, cat.Name, cat.FarmId)); }
public ActionResult Post(CatDto cat) { _catService.ProcessCat(cat); return(NoContent()); }