public async Task <IActionResult> AddHouse(AddHouseViewModel model) { if (!ModelState.IsValid) { foreach (var err in ModelState.Values.SelectMany(c => c.Errors)) { ViewData["addHouseError"] = err.ErrorMessage; } return(LocalRedirect($"/profile?error={ViewData["addHouseError"]}")); } if (model.Type.Equals(HouseType.None)) { ViewData["addHouseError"] = "Choose other house type"; return(LocalRedirect($"/profile?error={ViewData["addHouseError"]}")); } string path = "/images/" + model.ImageFile.FileName; using (var stream = new FileStream(_environment.WebRootPath + path, FileMode.OpenOrCreate)) { await model.ImageFile.CopyToAsync(stream); } var house = _mapper.Map <House>(model); house.ImagePath = path; house.OwnerId = Guid.Parse(HttpContext.User.Claims.First(c => ClaimTypes.NameIdentifier == c.Type).Value); house = await _houseService.Create(house); if (house == null) { ViewData["addHouseError"] = "Failed to publish house"; return(LocalRedirect($"/profile?error={ViewData["addHouseError"]}")); } return(RedirectToAction("ProfilePage", "Profile")); }
public async Task <JsonResult> Generate(int count) { var random = new Random(); var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; for (int i = 0; i < count; i++) { await _service.Create(new HouseDto { Number = random.Next(1, 100).ToString(), Address = new string(Enumerable.Repeat(chars, random.Next(2, 10)) .Select(s => s[random.Next(s.Length)]).ToArray()), Comment = new string(Enumerable.Repeat(chars, random.Next(1, 5)) .Select(s => s[random.Next(s.Length)]).ToArray()), AdditionalNumber = random.Next(10).ToString() }); } return(Json(count)); }
public async Task <IActionResult> Add(HouseForCreateDto house) { if (house == null) { return(BadRequest("Add object is null")); } var result = await _houseService.Create(house); if (result) { return(Ok("Created successfully")); } else { return(BadRequest("Failed to Create")); } }
public IActionResult Create(CreateHouseViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var house = _houseService.GetByCounterNumber(model.CounterNumber); if (house == null) { var newHouse = new House { IdentificationNumber = model.IdentificationNumber, Name = model.Name, Surname = model.Surname, Address = model.Address, CounterNumber = model.CounterNumber, ChiefId = User.Identity.GetId(), CreatedDate = DateTime.Now }; _houseService.Create(newHouse); _actionService.Create(new Core.Domain.Action { Endeks = 0, Price = 0, Description = string.Empty, Type = Core.Domain.Type.Read, CreatedDate = DateTime.Now, HouseId = newHouse.Id }); return(View("Success")); } ModelState.AddModelError(string.Empty, "Bu sayaç numarasına ait bir hane zaten mevcut"); return(View(model)); }