Esempio n. 1
0
        public async Task <IActionResult> Edit(Guid id, ImageCreateEditViewModel vm)
        {
            if (id != vm.Id)
            {
                return(BadRequest(new MessageDTO("Id and vm.id do not match")));
            }

            if (!await _bll.Images.ExistsAsync(vm.Id, User.UserGuidId()))
            {
                return(NotFound(new MessageDTO($"Current user does not have image with this id {id}")));
            }

            vm.AppUserId = User.UserGuidId();

            if (ModelState.IsValid)
            {
                await _bll.Images.UpdateAsync(_mapper.Map(vm));

                await _bll.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            vm.ItemSelectList = new SelectList(await _bll.Items.GetAllAsync(User.UserGuidId()), nameof(ItemBLL.Id), nameof(ItemBLL.Description), vm.ItemId);

            return(View(vm));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(Guid id, PriceCreateEditViewModel vm)
        {
            Console.WriteLine(vm.ItemId);
            if (id != vm.Id)
            {
                return(BadRequest(new MessageDTO("Id and vm.id do not match")));
            }

            if (!await _bll.Prices.ExistsAsync(id, User.UserGuidId()))
            {
                return(NotFound(new MessageDTO($"Price with this id {id} not found")));
            }

            vm.AppUserId = User.UserGuidId();

            if (ModelState.IsValid)
            {
                await _bll.Prices.UpdateAsync(_mapper.Map(vm));

                await _bll.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(vm));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(Guid id, PaymentCreateEditViewModel vm)
        {
            if (id != vm.Id)
            {
                return(BadRequest(new MessageDTO("Id and vm.id do not match")));
            }

            if (!await _bll.Payments.ExistsAsync(vm.Id, User.UserGuidId()))
            {
                return(NotFound(new MessageDTO($"Current user does not have payment with this id {id}")));
            }

            vm.AppUserId = User.UserGuidId();

            if (ModelState.IsValid)
            {
                await _bll.Payments.UpdateAsync(_mapper.Map(vm));

                await _bll.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            vm.CompanySelectList     = new SelectList(await _bll.Companies.GetAllAsync(User.UserGuidId()), nameof(CompanyBLL.Id), nameof(CompanyBLL.CompanyName), vm.CompanyId);
            vm.InvoiceSelectList     = new SelectList(await _bll.Invoices.GetAllAsync(User.UserGuidId()), nameof(InvoiceBLL.Id), nameof(InvoiceBLL.InvoiceNumber), vm.InvoiceId);
            vm.PaymentTypeSelectList = new SelectList(await _bll.PaymentTypes.GetAllAsync(), nameof(PaymentTypeBLL.Id), nameof(PaymentTypeBLL.Description), vm.PaymentTypeId);

            return(View(vm));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create(CompanyCreateEditViewModel vm)
        {
            vm.AppUserId = User.UserGuidId();

            if (ModelState.IsValid)
            {
                var bllEntity = _mapper.Map(vm);
                _bll.Companies.Add(bllEntity);
                await _bll.SaveChangesAsync();

                vm.Id = bllEntity.Id;
                var appUserCompanyBLL = new AppUserCompanyBLL()
                {
                    AppUserId = User.UserGuidId(),
                    CompanyId = bllEntity.Id
                };
                _bll.AppUserCompanies.Add(appUserCompanyBLL);
                await _bll.SaveChangesAsync();

                return(RedirectToAction(nameof(AppUserCompanies)));
            }
            vm.LocationSelectList = new SelectList(await _bll.Locations.GetAllAsync(User.UserGuidId()), nameof(LocationBLL.Id), nameof(LocationBLL.AddressLine), vm.LocationId);

            return(View(vm));
        }
Esempio n. 5
0
        // GET: Brands/Edit/5
        public async Task <IActionResult> Edit(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Brand brand;

            if (User.UserRole().Contains("Admin"))
            {
                brand = await _bll.BrandService
                        .FirstOrDefaultAsync((Guid)id);
            }
            else
            {
                brand = await _bll.BrandService
                        .FirstOrDefaultAsync((Guid)id, User.UserGuidId());
            }
            if (brand == null)
            {
                return(NotFound());
            }
            return(View(brand));
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(Guid id, Delivery delivery)
        {
            delivery.UserId = User.UserGuidId();

            if (id != delivery.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _bll.DeliveryService.UpdateAsync(delivery);

                    await _bll.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                }
                return(RedirectToAction(nameof(Index)));
            }
            var vm = new DeliveryViewModel()
            {
                Delivery = delivery,
                DeliveryTypesSelectList = new SelectList(
                    await _bll.DeliveryTypeService.AllAsync(), nameof(DeliveryType.Id), nameof(DeliveryType.Name)),
            };

            return(View(vm));
        }
Esempio n. 7
0
        // GET: Items/Details/5
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Item item;

            if (User.UserRole().Contains("Admin"))
            {
                item = await _bll.ItemService
                       .FirstOrDefaultAsync((Guid)id);
            }
            else
            {
                item = await _bll.ItemService
                       .FirstOrDefaultAsync((Guid)id, User.UserGuidId());
            }

            if (item == null)
            {
                return(NotFound());
            }

            return(View(item));
        }
Esempio n. 8
0
        // GET: Warehouses/Details/5
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Warehouse warehouse;

            if (User.UserRole().Contains("Admin"))
            {
                warehouse = await _bll.WarehouseService
                            .FirstOrDefaultAsync(id.Value);
            }
            else
            {
                warehouse = await _bll.WarehouseService
                            .FirstOrDefaultAsync(id.Value, User.UserGuidId());
            }

            if (warehouse == null)
            {
                return(NotFound());
            }

            var vm = new WarehouseItemsViewModel
            {
                Warehouse = warehouse
            };

            return(View(vm));
        }
Esempio n. 9
0
        // GET: Warehouses/Edit/5
        public async Task <IActionResult> Edit(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Warehouse warehouse;

            if (User.UserRole().Contains("Admin"))
            {
                warehouse = await _bll.WarehouseService
                            .FirstOrDefaultAsync(id.Value);
            }
            else
            {
                warehouse = await _bll.WarehouseService
                            .FirstOrDefaultAsync(id.Value, User.UserGuidId());
            }

            if (warehouse == null)
            {
                return(NotFound());
            }

            return(View(warehouse));
        }
Esempio n. 10
0
        public async Task <IActionResult> Edit(Guid id, ItemsBookedCreateEditViewModel vm)
        {
            if (id != vm.Id)
            {
                return(BadRequest(new MessageDTO("Id and vm.id do not match")));
            }

            if (!await _bll.ItemsBooked.ExistsAsync(id, User.UserGuidId()))
            {
                return(NotFound(new MessageDTO($"Booked Item with this id {id} not found")));
            }

            vm.AppUserId = User.UserGuidId();

            if (ModelState.IsValid)
            {
                await _bll.ItemsBooked.UpdateAsync(_mapper.Map(vm));

                await _bll.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            vm.BookingSelectList = new SelectList(await _bll.Bookings.GetAllAsync(User.UserGuidId()), nameof(BookingBLL.Id), nameof(BookingBLL.BookingNumber), vm.BookingId);
            vm.ItemSelectList    = new SelectList(await _bll.Items.GetAllAsync(User.UserGuidId()), nameof(ItemBLL.Id), nameof(ItemBLL.Description), vm.ItemId);

            return(View(vm));
        }
        public async Task <IActionResult> Edit(Guid id, AppUserCompanyCreateEditViewModel vm)
        {
            if (id != vm.Id)
            {
                return(BadRequest(new MessageDTO("Id and vm.id do not match")));
            }

            if (!await _bll.AppUserCompanies.ExistsAsync(vm.Id, User.UserGuidId()))
            {
                return(NotFound(new MessageDTO($"Current user does not have that company.")));
            }

            vm.AppUserId = User.UserGuidId();

            if (ModelState.IsValid)
            {
                await _bll.AppUserCompanies.UpdateAsync(_mapper.Map(vm), User.UserGuidId());

                await _bll.SaveChangesAsync();


                return(RedirectToAction(nameof(Index)));
            }
            vm.CompaniesSelectList = new SelectList(await _bll.Companies.GetAllAsync(User.UserGuidId()), nameof(CompanyBLL.Id), nameof(CompanyBLL.CompanyName), vm.CompanyId);
            return(View(vm));
        }
Esempio n. 12
0
        public async Task <IActionResult> Create(ImageCreateEditViewModel vm, IEnumerable <IFormFile> images)
        {
            vm.AppUserId = User.UserGuidId();

            if (ModelState.IsValid)
            {
                if (images != null)
                {
                    //Convert Image to byte and save to database
                    foreach (var file in images)
                    {
                        using (var ms = new MemoryStream())
                        {
                            //image.Save(ms, new PngEncoder());
                            var imageBLL = new ImageBLL();
                            imageBLL.AppUserId = User.UserGuidId();
                            await file.CopyToAsync(ms);

                            imageBLL.Picture = ms.ToArray();
                            imageBLL.ItemId  = vm.ItemId;
                            _bll.Images.Add(imageBLL);
                        }
                    }
                    await _bll.SaveChangesAsync();
                }

                return(RedirectToAction(nameof(Index)));
            }
            vm.ItemSelectList = new SelectList(await _bll.Items.GetAllAsync(User.UserGuidId()), nameof(ItemBLL.Id), nameof(ItemBLL.Description), vm.ItemId);

            return(View(vm));
        }
Esempio n. 13
0
        public async Task <IActionResult> ClearCart(Guid id)
        {
            await _bll.ItemInCartService.RemoveAllCartItems(id, User.UserGuidId());

            await _bll.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 14
0
        /// <summary>
        ///  Clear wish list
        /// </summary>
        /// <returns>View</returns>
        public async Task <IActionResult> Clear()
        {
            await _bll.UserWishListService.RemoveUsersWishListAsync(User.UserGuidId());

            await _bll.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 15
0
        // GET: Images/Create
        public async Task <IActionResult> Create()
        {
            var vm = new ImageCreateEditViewModel
            {
                ItemSelectList = new SelectList(await _bll.Items.GetAllAsync(User.UserGuidId()), nameof(ItemBLL.Id), nameof(ItemBLL.Description))
            };

            return(View(vm));
        }
Esempio n. 16
0
        // GET: Companies/Create
        public async Task <IActionResult> Create()
        {
            var vm = new CompanyCreateEditViewModel
            {
                LocationSelectList = new SelectList(await _bll.Locations.GetAllAsync(User.UserGuidId()), nameof(LocationBLL.Id), nameof(LocationBLL.AddressLine))
            };

            return(View(vm));
        }
Esempio n. 17
0
        // GET: ItemOwnerships/Create
        public async Task <IActionResult> Create()
        {
            var vm = new ItemOwnershipCreateEditViewModel
            {
                CompanySelectList = new SelectList(await _bll.Companies.GetAllAsync(User.UserGuidId()), nameof(CompanyBLL.Id), nameof(CompanyBLL.CompanyName)),
                ItemSelectList    = new SelectList(await _bll.Items.GetAllAsync(User.UserGuidId()), nameof(ItemBLL.Id), nameof(ItemBLL.Description))
            };

            return(View(vm));
        }
Esempio n. 18
0
        public async Task <IActionResult> DeleteConfirmed(Guid id)
        {
            var removeAsync = !User.UserRole().Contains("Admin")
                ? await _bll.BrandService.RemoveAsync(id, User.UserGuidId())
                : await _bll.BrandService.RemoveAsync(id);

            await _bll.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 19
0
        // GET: ItemsBooked/Create
        public async Task <IActionResult> Create()
        {
            var vm = new ItemsBookedCreateEditViewModel
            {
                BookingSelectList = new SelectList(await _bll.Bookings.GetAllAsync(User.UserGuidId()), nameof(BookingBLL.Id), nameof(BookingBLL.BookingNumber)),
                ItemSelectList    = new SelectList(await _bll.Items.GetAllAsync(User.UserGuidId()), nameof(ItemBLL.Id), nameof(ItemBLL.Description))
            };

            return(View(vm));
        }
Esempio n. 20
0
        /// <summary>
        ///  Clear cart confirmation
        /// </summary>
        /// <param name="cartId">Cart Id</param>
        /// <returns>View</returns>
        public async Task <IActionResult> Clear(Guid?cartId)
        {
            if (cartId == null)
            {
                return(NotFound());
            }
            var cart = await _bll.CartService.GetCartAsync(User.UserGuidId());

            return(View(cart));
        }
Esempio n. 21
0
        // GET: Images/Details/5
        public async Task <IActionResult> Details(Guid id)
        {
            var image = await _bll.Images.FirstOrDefaultAsync(id, User.UserGuidId());

            if (image == null)
            {
                return(NotFound(new MessageDTO($"AppUser image with id {id} not found")));
            }

            return(View(_mapper.Map(image)));
        }
Esempio n. 22
0
        // GET: ItemsBooked/Delete/5
        public async Task <IActionResult> Delete(Guid id)
        {
            var itemBooked = await _bll.ItemsBooked.FirstOrDefaultAsync(id, User.UserGuidId());

            if (itemBooked == null)
            {
                return(NotFound(new MessageDTO("ItemBooked not found")));
            }

            return(View(_mapper.Map(itemBooked)));
        }
        // GET: AppUserCompany/Delete/5
        public async Task <IActionResult> Delete(Guid id)
        {
            var appUserCompany = await _bll.AppUserCompanies.FirstOrDefaultAsync(id, User.UserGuidId());

            if (appUserCompany == null)
            {
                return(NotFound(new MessageDTO("AppUserCompany not found")));
            }

            return(View(_mapper.Map(appUserCompany)));
        }
Esempio n. 24
0
        // GET: Bookings/Details/5
        public async Task <IActionResult> Details(Guid id)
        {
            var booking = await _bll.Bookings.FirstOrDefaultAsync(id, User.UserGuidId());

            if (booking == null)
            {
                return(NotFound(new MessageDTO($"Booking with id {id} not found")));
            }

            return(View(_mapper.Map(booking)));
        }
Esempio n. 25
0
        // GET: ItemCategories/Details/5
        public async Task <IActionResult> Details(Guid id)
        {
            var itemCategory = await _bll.ItemCategories.FirstOrDefaultAsync(id, User.UserGuidId());

            if (itemCategory == null)
            {
                return(NotFound(new MessageDTO($"Item category with id {id} not found")));
            }

            return(View(_mapper.Map(itemCategory)));
        }
Esempio n. 26
0
        // GET: Payments/Details/5
        public async Task <IActionResult> Details(Guid id)
        {
            var payment = await _bll.Payments.FirstOrDefaultAsync(id, User.UserGuidId());

            if (payment == null)
            {
                return(NotFound(new MessageDTO($"AppUser company with id {id} not found")));
            }

            return(View(_mapper.Map(payment)));
        }
Esempio n. 27
0
        public async Task <IActionResult> Delete(Guid id)
        {
            var payment = await _bll.Payments.FirstOrDefaultAsync(id, User.UserGuidId());

            if (payment == null)
            {
                return(NotFound(new MessageDTO("Payment not found")));
            }

            return(View(_mapper.Map(payment)));
        }
Esempio n. 28
0
        // GET: Locations/Delete/5
        public async Task <IActionResult> Delete(Guid id)
        {
            var location = await _bll.Locations.FirstOrDefaultAsync(id, User.UserGuidId());

            if (location == null)
            {
                return(NotFound(new MessageDTO("Location not found")));
            }

            return(View(_mapper.Map(location)));
        }
Esempio n. 29
0
        /// <summary>
        /// Get all information to pay and delivery
        /// </summary>
        /// <param name="cartId">Cart Id</param>
        /// <param name="typeId">DeliveryType Id</param>
        /// <param name="bank">bank name with maksekeskus url -> "{bank name};url"</param>
        /// <param name="omniva_selection_value1">Omniva destination</param>
        /// <param name="address">Address destination</param>
        /// <returns></returns>
        // ReSharper disable once InconsistentNaming
        public async Task <IActionResult> Pay(Guid?cartId, Guid?typeId, string bank, string?omniva_selection_value1, string?address)
        {
            var bankName    = bank.Split(";")[0].Replace("{", "").Replace("}", "");
            var url         = bank.Split(";")[1];
            var destination = address ?? omniva_selection_value1;

            if (cartId == null || typeId == null || destination == null)
            {
                return(NotFound());
            }

            var deliveryType = await _bll.DeliveryTypeService.FirstOrDefaultAsync(typeId.Value);

            var cart = await _bll.CartService.GetCartAsync(User.UserGuidId());

            var delivery = new Delivery
            {
                Id             = Guid.NewGuid(),
                Destination    = destination,
                Cost           = deliveryType.DeliveryCost,
                DeliveryTypeId = typeId.Value,
                UserId         = User.UserGuidId(),
            };

            _bll.DeliveryService.CreateDelivery(delivery, cart.CartItems);

            var returnOkUrl = Url.PageLink().Contains("localhost") ? "https://localhost:5001/Deliveries"
                : "https://mamkupi.azurewebsites.net/DELIVERIES";

            var returnNotOkUrl = Url.PageLink().Contains("localhost") ? "https://localhost:5001"
                : "https://mamkupi.azurewebsites.net";

            var returnOk = new Dictionary <string, string>
            {
                ["url"]    = returnOkUrl,
                ["method"] = "GET"
            };

            var returnNotOk = new Dictionary <string, string>
            {
                ["url"]    = returnNotOkUrl,
                ["method"] = "GET"
            };

            var trans = new Dictionary <string, dynamic>
            {
                ["return_url"]       = returnOk,
                ["cancel_url"]       = returnNotOk,
                ["notification_url"] = returnNotOk,
            };

            var transactionDict = new Dictionary <string, dynamic>
            {
Esempio n. 30
0
        /// <summary>
        /// Remove item from cart
        /// </summary>
        /// <param name="id">item in cart Id</param>
        /// <returns></returns>
        public async Task <IActionResult> RemoveProduct(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            await _bll.ItemInCartService.RemoveAsync(id.Value, User.UserGuidId());

            await _bll.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }