Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        //[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);
        }
Esempio n. 4
0
        public string Post([FromBody] CatDto cat)
        {
            var domainCat = cat.Map();

            _catService.Insert(domainCat);

            return("Inserted");
        }
Esempio n. 5
0
        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());
        }
Esempio n. 8
0
        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));
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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));
        }
Esempio n. 13
0
        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();
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
 public static Cat Map(this CatDto cat)
 {
     return(new Cat(cat.Id, cat.Name, cat.FarmId));
 }
Esempio n. 18
0
 public ActionResult Post(CatDto cat)
 {
     _catService.ProcessCat(cat);
     return(NoContent());
 }