Beispiel #1
0
 internal async Task UpdateAsync(ApplicationUser user, Adress adress)
 {
     adress = await GetOrCreateAdress(adress);
     user.Adress = adress;
     user.AdressId = adress.Id;
     _db.Entry(user).State = EntityState.Modified;
     await _db.SaveChangesAsync();
 }
        public async Task<ActionResult> Create([Bind(Include = "Id,Name,Date,Price")] MarketEvents marketEvents, Adress adress)
        {
            if (ModelState.IsValid)
            {
                marketEvents.Adress = await AdressManager.GetOrCreateAdress(adress);
                marketEvents.AdressId = marketEvents.Adress.Id;
                _db.MarketEvents.Add(marketEvents);
                await _db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            return View(marketEvents);
        }
Beispiel #3
0
        public async Task<Adress> GetOrCreateAdress(string sity, string street, string house)
        {
            var adress = await _db.Adresses.FirstOrDefaultAsync(o => o.Sity.Equals(sity) && o.Street.Equals(street) && o.House.Equals(house));
            if (adress != null) return adress;
            adress = new Adress
            {
                Id = Guid.NewGuid().ToString(),
                Sity = sity,
                Street = street,
                House = house
            };
            _db.Entry(adress).State = EntityState.Added;
            await _db.SaveChangesAsync();

            return adress;
        }
Beispiel #4
0
 public async Task<Adress> GetOrCreateAdress(Adress model)
 {
     var adress = await _db.Adresses.FirstOrDefaultAsync(o => o.Sity.Equals(model.Sity) &&
         o.Street.Equals(model.Street) && o.House.Equals(model.House));
     if (adress != null)
     {
         _db.Entry(adress).State = EntityState.Unchanged;
     }
     else
     {
         adress = model;
         adress.Id = Guid.NewGuid().ToString();
         _db.Entry(adress).State = EntityState.Added;
     }
     
     await _db.SaveChangesAsync();
     return adress;
 }
Beispiel #5
0
 public Shop CreateShop(Adress adress)
 {
     var shop = new Shop { Adress = adress };
     if (adress != null) shop.AdressId = adress.Id;
     return shop;
 }
Beispiel #6
0
 private async Task SaveAdress(Adress adress, string userid)
 {
     var user = await UserManager.FindByIdAsync(userid);
     await AdressManager.UpdateAsync(user, adress);
 }
Beispiel #7
0
        public async Task<ActionResult> Create(CreateOrderViewModel model, Adress adress)
        {
            ValidateAdress(model.AdresShipping ?? adress);
            ValidateProduct(model.Products);
            if (ModelState.IsValid)
            {
                if (model.AdresShipping == null) model.AdresShipping = adress;
                await CreateOrder(model);
                return RedirectToAction("Index", "Products");
            }

            await InitListTypes(model);
            return View(model);
        }
Beispiel #8
0
 public async Task<ActionResult> Edit(CreateOrderViewModel model, Adress adress)
 {
     if (model.AdresShipping == null) model.AdresShipping = adress;
     if (ModelState.IsValid)
     {
         await ModifyOrder(model);
         return RedirectToAction("Index");
     }
     if (string.IsNullOrEmpty(model.AdresShipping?.FullAdress))
         ModelState.AddModelError("AdresShipping", "Необхідно вказати адресу");
     await InitListTypes(model);
     return View(model);
 }
Beispiel #9
0
 private void ValidateAdress(Adress model)
 {
     if (model == null)
         ModelState.AddModelError("AdresShipping", "Необхідно вказати адресу");
     if (string.IsNullOrEmpty(model?.Sity))
         ModelState.AddModelError("AdresShipping", "Необхідно вказати місто");
     if (string.IsNullOrEmpty(model?.Street))
         ModelState.AddModelError("AdresShipping", "Необхідно вказати вулицю");
     if (string.IsNullOrEmpty(model?.House))
         ModelState.AddModelError("AdresShipping", "Необхідно вказати номер будинка");
 }
 public async Task<ActionResult> Edit([Bind(Include = "Id,Name,Date,Price")] MarketEvents marketEvents, Adress adress)
 {
     if (ModelState.IsValid)
     {
         var events = await _db.MarketEvents.FindAsync(marketEvents.Id);
         if(events == null) return RedirectToAction("Index");
         adress = await AdressManager.GetOrCreateAdress(adress);
         events.AdressId = adress.Id;
         events.Name = marketEvents.Name;
         events.Date = marketEvents.Date;
         events.Price = marketEvents.Price;
         _db.Entry(events).State = EntityState.Modified;
         await _db.SaveChangesAsync();
         return RedirectToAction("Index");
     }
     return View(marketEvents);
 }