Example #1
0
        public async Task <IActionResult> Create(RegionViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var model           = vm.ToModel();
                var createOperation = await _bo.CreateAsync(model);

                if (!createOperation.Success)
                {
                    return(OperationErrorBackToIndex(createOperation.Exception));
                }
                if (!createOperation.Result)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Message);
                    ViewData["Title"] = "Create Region";
                    var crumbs = GetCrumbs();
                    crumbs.Add(new BreadCrumb()
                    {
                        Action = "Create", Controller = "Regions", Icon = "fa-search", Text = "Create"
                    });
                    ViewData["BreadCrumbs"] = crumbs;
                    return(View(vm));
                }
                return(OperationSuccess("The record was successfuly created"));
            }
            return(View(vm));
        }
        public async Task <IActionResult> Edit(Guid id, TitleViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync(id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                if (!vm.CompareToModel(result))
                {
                    result = vm.ToModel(result);
                    var updateOperation = await _bo.UpdateAsync(result);

                    if (!updateOperation.Success)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);
                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id, Description, Stars, Date, InterestPointId, VisitorId")] FeedbackViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync((Guid)id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(NotFound());
                }
                var result = getOperation.Result;
                result.Description     = vm.Description;
                result.Stars           = vm.Stars;
                result.Date            = vm.Date;
                result.InterestPointId = vm.InterestPointId;
                result.VisitorId       = vm.VisitorId;
                var updateOperation = await _bo.UpdateAsync(result);

                if (!updateOperation.Success)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);
                    return(View(vm));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly updated"));
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id, FirstName, LastName, BirthDate, Gender, ProfileId, CountryId")] VisitorViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync((Guid)id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                result.FirstName = vm.FirstName;
                result.LastName  = vm.LastName;
                result.BirthDate = vm.BirthDate;
                result.Gender    = vm.Gender;
                result.ProfileId = vm.ProfileId;
                result.CountryId = vm.CountryId;
                var updateOperation = await _bo.UpdateAsync(result);

                if (!updateOperation.Success)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);
                    return(View(vm));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly updated"));
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Example #5
0
        public async Task <IActionResult> Create(BrandViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var model           = vm.ToModel();
                var createOperation = await _bo.CreateAsync(model);

                if (!createOperation.Success)
                {
                    return(OperationErrorBackToIndex(createOperation.Exception));
                }
                if (!createOperation.Result)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Message);

                    Draw("Create", "fa-plus");

                    return(View());
                }
                else
                {
                    return(OperationSuccess("The record was successfuly created"));
                }
            }
            return(View(vm));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Description, PhotoPath")] ProfileViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync((Guid)id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                result.Description = vm.Description;
                result.PhotoPath   = vm.PhotoPath;
                var updateOperation = await _bo.UpdateAsync(result);

                if (!updateOperation.Success)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);
                    return(View(vm));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly updated"));
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(ReservedQueueViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var model           = vm.ToReservedQueue();
                var createOperation = await _bo.CreateAsync(model);

                if (!createOperation.Success)
                {
                    return(OperationErrorBackToIndex(createOperation.Exception));
                }
                if (!createOperation.Result)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Message);

                    var listEstOperation = await _ebo.ListNotDeletedAsync();

                    if (!listEstOperation.Success)
                    {
                        return(OperationErrorBackToIndex(listEstOperation.Exception));
                    }

                    var listProOperation = await _pbo.ListNotDeletedAsync();

                    if (!listProOperation.Success)
                    {
                        return(OperationErrorBackToIndex(listProOperation.Exception));
                    }

                    var estList = new List <SelectListItem>();
                    foreach (var item in listEstOperation.Result)
                    {
                        estList.Add(new SelectListItem()
                        {
                            Value = item.Id.ToString(), Text = item.Address
                        });
                    }

                    var profiList = new List <SelectListItem>();
                    foreach (var item in listProOperation.Result)
                    {
                        profiList.Add(new SelectListItem()
                        {
                            Value = item.Id.ToString(), Text = item.VatNumber.ToString()
                        });
                    }
                    ViewBag.Establishments = estList;
                    ViewBag.Profiles       = profiList;

                    Draw("Create", "fa-plus");
                    return(View(vm));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly created"));
                }
            }
            return(View(vm));
        }
Example #8
0
        public async Task <IActionResult> Edit(Guid id, ShoppingBasketViewModel vm)
        {
            var listROperation = await _pbo.ListNotDeletedAsync();

            if (!listROperation.Success)
            {
                return(OperationErrorBackToIndex(listROperation.Exception));
            }
            var pList = new List <SelectListItem>();

            foreach (var item in listROperation.Result)
            {
                var listItem = new SelectListItem()
                {
                    Value = item.Id.ToString(), Text = item.VatNumber.ToString()
                };
                if (item.Id == vm.ProfileId)
                {
                    listItem.Selected = true;
                }
                pList.Add(listItem);
            }
            ViewBag.Regions = pList;

            Draw("Edit", "fa-edit");

            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync(id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                if (!vm.CompareToModel(result))
                {
                    result = vm.ToModel(result);
                    var updateOperation = await _bo.UpdateAsync(result);

                    if (!updateOperation.Success)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);


                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(MenuViewModel vm)
        {
            var listMealOperation = await _mbo.ListNonDeletedAsync();

            if (!listMealOperation.Success)
            {
                return(OperationErrorBackToIndex(listMealOperation.Exception));
            }

            var listRestOperation = await _rbo.ListNonDeletedAsync();

            if (!listRestOperation.Success)
            {
                return(OperationErrorBackToIndex(listRestOperation.Exception));
            }

            var mealList = new List <SelectListItem>();

            foreach (var item in listMealOperation.Result)
            {
                mealList.Add(new SelectListItem()
                {
                    Value = item.Id.ToString(), Text = item.Name
                });
            }

            var restList = new List <SelectListItem>();

            foreach (var item in listRestOperation.Result)
            {
                restList.Add(new SelectListItem()
                {
                    Value = item.Id.ToString(), Text = item.Name
                });
            }

            ViewBag.Meals       = mealList;
            ViewBag.Restaurants = restList;

            if (ModelState.IsValid)
            {
                var model           = vm.ToModel();
                var createOperation = await _bo.CreateAsync(model);

                if (!createOperation.Success)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Exception);
                    return(View(vm));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly created"));
                }
            }
            return(View(vm));
        }
        public async Task <IActionResult> Register(RegisterViewModel vm)
        {
            var accountBo         = new AccountBusinessController(UserManager, RoleManager);
            var profile           = new Profile(vm.VatNumber, vm.FirstName, vm.LastName, vm.PhoneNumber, vm.BirthDate);
            var registerOperation = await accountBo.Register(vm.UserName, vm.Email, vm.Password, profile, vm.Role);

            if (registerOperation.Success)
            {
                return(OperationSuccess("The account was successfuly registered!"));
            }
            TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, registerOperation.Message);
            return(View(vm));
        }
        public async Task <IActionResult> Login(LoginViewModel vm)
        {
            var loginOperation = await SignInManager.PasswordSignInAsync(vm.UserName, vm.Password, false, false);

            if (loginOperation.Succeeded)
            {
                return(OperationSuccess("Welcome User"));
            }
            else
            {
                TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, loginOperation.ToString());
                return(View(vm));
            }
        }
        public async Task <IActionResult> New(DishViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var model           = vm.ToModel();
                var createOperation = await _bo.CreateAsync(model);

                if (!createOperation.Success)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Exception);
                    return(View(vm));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly created"));
                }
            }
            return(View(vm));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id, Name, Description, Address, PhotoPath, OpeningHours, " +
                                                              "ClosingHours, ClosingDays, CovidSafe, Status, CompanyId")] InterestPointViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync((Guid)id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                result.Name         = vm.Name;
                result.Description  = vm.Description;
                result.Address      = vm.Address;
                result.PhotoPath    = vm.PhotoPath;
                result.OpeningHours = vm.OpeningHours;
                result.ClosingHours = vm.ClosingHours;
                result.ClosingDays  = vm.ClosingDays;
                result.CovidSafe    = vm.CovidSafe;
                result.Status       = vm.Status;
                result.CompanyId    = vm.CompanyId;
                var updateOperation = await _bo.UpdateAsync(result);

                if (!updateOperation.Success)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);
                    return(View(vm));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly updated"));
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Example #14
0
        public async Task <IActionResult> Register(RegisterViewModel vm)
        {
            var accountBo         = new AccountBusinessController(UserManager, RoleManager);
            var person            = new Profile(vm.Description, vm.PhotoPath);
            var registerOperation = await accountBo.Register(vm.UserName, vm.Email, vm.Password, person, vm.Role);

            if (registerOperation.Success)
            {
                if (vm.Role == "Visitor")
                {
                    return(RedirectToAction("Create", "Visitors"));
                }
                if (vm.Role == "Company")
                {
                    return(RedirectToAction("Create", "Companies"));
                }
            }
            //return OperationSuccess("The account was successfuly registered!");
            TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, registerOperation.Message);

            return(View(vm));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name, Representative, PhoneNumber, VatNumber, ProfileId")] CompanyViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync((Guid)id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                if (!vm.CompareToModel(result))
                {
                    result.Name           = vm.Name;
                    result.Representative = vm.Representative;
                    result.PhoneNumber    = vm.PhoneNumber;
                    result.VatNumber      = vm.VatNumber;
                    result.ProfileId      = vm.ProfileId;
                    var updateOperation = await _bo.UpdateAsync(result);

                    if (!updateOperation.Success)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);
                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task<IActionResult> Create(EstablishmentViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var model = vm.ToModel();
                var createOperation = await _bo.CreateAsync(model);
                if (!createOperation.Success) return OperationErrorBackToIndex(createOperation.Exception);
                if (!createOperation.Result)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Message);

                    var listCOperation = await _cbo.ListNotDeletedAsync();
                    if (!listCOperation.Success) return OperationErrorBackToIndex(listCOperation.Exception);
                    var cList = new List<SelectListItem>();
                    foreach (var item in listCOperation.Result)
                    {
                        cList.Add(new SelectListItem() { Value = item.Id.ToString(), Text = item.Name });
                    }

                    var listROperation = await _rbo.ListNotDeletedAsync();
                    if (!listROperation.Success) return OperationErrorBackToIndex(listROperation.Exception);
                    var rList = new List<SelectListItem>();
                    foreach (var item in listROperation.Result)
                    {
                        rList.Add(new SelectListItem() { Value = item.Id.ToString(), Text = item.Name });
                    }

                    ViewBag.Regions = rList;
                    ViewBag.Companies = cList;
                    Draw("Create", "fa-plus");
                    return View();
                }
                else return OperationSuccess("The record was successfuly created");
            }
            return View(vm);
        }
Example #17
0
 private IActionResult OperationSuccess(string message)
 {
     TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Success, message);
     return(RedirectToAction(nameof(Index)));
 }
Example #18
0
 private IActionResult OperationErrorBackToIndex(Exception exception)
 {
     TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, exception);
     return(RedirectToAction(nameof(Index)));
 }
Example #19
0
 private IActionResult RecordNotFound()
 {
     TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Information, "The record was not found");
     return(RedirectToAction(nameof(Index)));
 }
        public async Task <IActionResult> Edit(Guid id, ProductModelViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync(id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                if (!vm.CompareToModel(result))
                {
                    result = vm.ToModel(result);
                    var updateOperation = await _bo.UpdateAsync(result);

                    if (!updateOperation.Success)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);

                        getOperation = await _bo.ReadAsync((Guid)id);

                        if (!getOperation.Success)
                        {
                            return(OperationErrorBackToIndex(getOperation.Exception));
                        }
                        if (getOperation.Result == null)
                        {
                            return(RecordNotFound());
                        }

                        vm = ProductModelViewModel.Parse(getOperation.Result);

                        var listBOperation = await _bbo.ListNotDeletedAsync();

                        if (!listBOperation.Success)
                        {
                            return(OperationErrorBackToIndex(listBOperation.Exception));
                        }
                        var listCOperation = await _cbo.ListNotDeletedAsync();

                        if (!listCOperation.Success)
                        {
                            return(OperationErrorBackToIndex(listCOperation.Exception));
                        }

                        ViewBag.Measure = Enum.GetNames(typeof(Measure)).Select(r => new SelectListItem {
                            Text = r, Value = r
                        });;
                        var bList = new List <SelectListItem>();
                        foreach (var item in listBOperation.Result)
                        {
                            var listItem = new SelectListItem()
                            {
                                Value = item.Id.ToString(), Text = item.Name
                            };
                            if (item.Id == vm.BrandId)
                            {
                                listItem.Selected = true;
                            }
                            bList.Add(listItem);
                        }
                        ViewBag.Brands = bList;

                        var cList = new List <SelectListItem>();
                        foreach (var item in listCOperation.Result)
                        {
                            var listItem = new SelectListItem()
                            {
                                Value = item.Id.ToString(), Text = item.Name
                            };
                            if (item.Id == vm.BrandId)
                            {
                                listItem.Selected = true;
                            }
                            cList.Add(listItem);
                        }
                        ViewBag.Categories = cList;

                        Draw("Edit", "fa-edit");

                        return(View(vm));
                    }
                    if (!updateOperation.Result)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Message);

                        getOperation = await _bo.ReadAsync((Guid)id);

                        if (!getOperation.Success)
                        {
                            return(OperationErrorBackToIndex(getOperation.Exception));
                        }
                        if (getOperation.Result == null)
                        {
                            return(RecordNotFound());
                        }

                        vm = ProductModelViewModel.Parse(getOperation.Result);

                        var listBOperation = await _bbo.ListNotDeletedAsync();

                        if (!listBOperation.Success)
                        {
                            return(OperationErrorBackToIndex(listBOperation.Exception));
                        }
                        var listCOperation = await _cbo.ListNotDeletedAsync();

                        if (!listCOperation.Success)
                        {
                            return(OperationErrorBackToIndex(listCOperation.Exception));
                        }

                        ViewBag.Measure = Enum.GetNames(typeof(Measure)).Select(r => new SelectListItem {
                            Text = r, Value = r
                        });;

                        var bList = new List <SelectListItem>();
                        foreach (var item in listBOperation.Result)
                        {
                            var listItem = new SelectListItem()
                            {
                                Value = item.Id.ToString(), Text = item.Name
                            };
                            if (item.Id == vm.BrandId)
                            {
                                listItem.Selected = true;
                            }
                            bList.Add(listItem);
                        }
                        ViewBag.Brands = bList;

                        var cList = new List <SelectListItem>();
                        foreach (var item in listCOperation.Result)
                        {
                            var listItem = new SelectListItem()
                            {
                                Value = item.Id.ToString(), Text = item.Name
                            };
                            if (item.Id == vm.BrandId)
                            {
                                listItem.Selected = true;
                            }
                            cList.Add(listItem);
                        }
                        ViewBag.Categories = cList;

                        Draw("Edit", "fa-edit");

                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(Guid id, ProductUnitViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync(id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                if (!vm.CompareToModel(result))
                {
                    result = vm.ToModel(result);
                    var updateOperation = await _bo.UpdateAsync(result);

                    if (!updateOperation.Success)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);

                        getOperation = await _bo.ReadAsync((Guid)id);

                        if (!getOperation.Success)
                        {
                            return(OperationErrorBackToIndex(getOperation.Exception));
                        }
                        if (getOperation.Result == null)
                        {
                            return(RecordNotFound());
                        }

                        vm = ProductUnitViewModel.Parse(getOperation.Result);

                        var listPMOperation = await _pmbo.ListNotDeletedAsync();

                        if (!listPMOperation.Success)
                        {
                            return(OperationErrorBackToIndex(listPMOperation.Exception));
                        }

                        var pmList = new List <SelectListItem>();
                        foreach (var item in listPMOperation.Result)
                        {
                            pmList.Add(new SelectListItem()
                            {
                                Value = item.Id.ToString(), Text = item.Name
                            });
                        }
                        ViewBag.ProductModels = pmList;


                        var listEOperation = await _ebo.ListNotDeletedAsync();

                        if (!listEOperation.Success)
                        {
                            return(OperationErrorBackToIndex(listEOperation.Exception));
                        }

                        var eList = new List <SelectListItem>();
                        foreach (var item in listEOperation.Result)
                        {
                            var company = await _cbo.ReadAsync(item.CompanyId);

                            var listItem = new SelectListItem()
                            {
                                Value = item.Id.ToString(), Text = company.Result.Name + ", " + item.Address
                            };
                            if (item.Id == vm.EstablishmentId)
                            {
                                listItem.Selected = true;
                            }
                            eList.Add(listItem);
                        }
                        ViewBag.Establishments = eList;

                        var listSBOperation = await _sbbo.ListNotDeletedAsync();

                        if (!listSBOperation.Success)
                        {
                            return(OperationErrorBackToIndex(listSBOperation.Exception));
                        }

                        var sbList = new List <SelectListItem>();
                        foreach (var item in listSBOperation.Result)
                        {
                            var profile = await _pbo.ReadAsync(item.ProfileId);

                            var listItem = new SelectListItem()
                            {
                                Value = item.Id.ToString(), Text = profile.Result.VatNumber.ToString()
                            };
                            if (item.Id == vm.ProductModelId)
                            {
                                listItem.Selected = true;
                            }
                            sbList.Add(listItem);
                        }
                        ViewBag.ShoppingBaskets = sbList;

                        Draw("Edit", "fa-edit");

                        return(View(vm));
                    }
                    if (!updateOperation.Result)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Message);

                        getOperation = await _bo.ReadAsync((Guid)id);

                        if (!getOperation.Success)
                        {
                            return(OperationErrorBackToIndex(getOperation.Exception));
                        }
                        if (getOperation.Result == null)
                        {
                            return(RecordNotFound());
                        }

                        vm = ProductUnitViewModel.Parse(getOperation.Result);

                        var listEOperation = await _ebo.ListNotDeletedAsync();

                        if (!listEOperation.Success)
                        {
                            return(OperationErrorBackToIndex(listEOperation.Exception));
                        }

                        var listPMOperation = await _pmbo.ListNotDeletedAsync();

                        if (!listPMOperation.Success)
                        {
                            return(OperationErrorBackToIndex(listPMOperation.Exception));
                        }

                        var pmList = new List <SelectListItem>();
                        foreach (var item in listPMOperation.Result)
                        {
                            pmList.Add(new SelectListItem()
                            {
                                Value = item.Id.ToString(), Text = item.Name
                            });
                        }
                        ViewBag.ProductModels = pmList;


                        var eList = new List <SelectListItem>();
                        foreach (var item in listEOperation.Result)
                        {
                            var company = await _cbo.ReadAsync(item.CompanyId);

                            var listItem = new SelectListItem()
                            {
                                Value = item.Id.ToString(), Text = company.Result.Name + ", " + item.Address
                            };
                            if (item.Id == vm.EstablishmentId)
                            {
                                listItem.Selected = true;
                            }
                            eList.Add(listItem);
                        }
                        ViewBag.Establishments = eList;

                        var listSBOperation = await _sbbo.ListNotDeletedAsync();

                        if (!listSBOperation.Success)
                        {
                            return(OperationErrorBackToIndex(listSBOperation.Exception));
                        }

                        var sbList = new List <SelectListItem>();
                        foreach (var item in listSBOperation.Result)
                        {
                            var profile = await _pbo.ReadAsync(item.ProfileId);

                            var listItem = new SelectListItem()
                            {
                                Value = item.Id.ToString(), Text = profile.Result.VatNumber.ToString()
                            };
                            if (item.Id == vm.ProductModelId)
                            {
                                listItem.Selected = true;
                            }
                            sbList.Add(listItem);
                        }
                        ViewBag.ShoppingBaskets = sbList;

                        Draw("Edit", "fa-edit");

                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(ProductUnitViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var model           = vm.ToModel();
                var createOperation = await _bo.CreateAsync(model);

                if (!createOperation.Success)
                {
                    return(OperationErrorBackToIndex(createOperation.Exception));
                }
                if (!createOperation.Result)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Message);

                    var listEOperation = await _ebo.ListNotDeletedAsync();

                    if (!listEOperation.Success)
                    {
                        return(OperationErrorBackToIndex(listEOperation.Exception));
                    }

                    var eList = new List <SelectListItem>();
                    foreach (var item in listEOperation.Result)
                    {
                        var company = await _cbo.ReadAsync(item.CompanyId);

                        eList.Add(new SelectListItem()
                        {
                            Value = item.Id.ToString(), Text = company.Result.Name + ", " + item.Address
                        });
                    }

                    var listSBOperation = await _sbbo.ListNotDeletedAsync();

                    if (!listSBOperation.Success)
                    {
                        return(OperationErrorBackToIndex(listSBOperation.Exception));
                    }

                    var sbList = new List <SelectListItem>();
                    foreach (var item in listSBOperation.Result)
                    {
                        var profile = await _pbo.ReadAsync(item.ProfileId);

                        sbList.Add(new SelectListItem()
                        {
                            Value = item.Id.ToString(), Text = profile.Result.VatNumber.ToString()
                        });
                    }

                    var listPMOperation = await _pmbo.ListNotDeletedAsync();

                    if (!listPMOperation.Success)
                    {
                        return(OperationErrorBackToIndex(listPMOperation.Exception));
                    }

                    var pmList = new List <SelectListItem>();
                    foreach (var item in listPMOperation.Result)
                    {
                        pmList.Add(new SelectListItem()
                        {
                            Value = item.Id.ToString(), Text = item.Name
                        });
                    }

                    ViewBag.Establishments  = eList;
                    ViewBag.ShoppingBaskets = sbList;
                    ViewBag.ProductModels   = pmList;

                    Draw("Create", "fa-plus");

                    return(View(vm));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly created"));
                }
            }
            return(View(vm));
        }
        public async Task<IActionResult> Edit(Guid id, EstablishmentViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync(id);
                if (!getOperation.Success) return OperationErrorBackToIndex(getOperation.Exception);
                if (getOperation.Result == null) return RecordNotFound();
                var result = getOperation.Result;

                if (!vm.CompareToModel(result))
                {
                    result = vm.ToModel(result);
                    var updateOperation = await _bo.UpdateAsync(result);
                    if (!updateOperation.Success)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);
                        getOperation = await _bo.ReadAsync((Guid)id);
                        if (!getOperation.Success) return OperationErrorBackToIndex(getOperation.Exception);
                        if (getOperation.Result == null) return RecordNotFound();

                        var listROperation = await _rbo.ListNotDeletedAsync();
                        if (!listROperation.Success) return OperationErrorBackToIndex(listROperation.Exception);
                        var rList = new List<SelectListItem>();
                        foreach (var item in listROperation.Result)
                        {
                            var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name };
                            if (item.Id == vm.RegionId) listItem.Selected = true;
                            rList.Add(listItem);
                        }
                        ViewBag.Regions = rList;

                        var listCOperation = await _cbo.ListNotDeletedAsync();
                        if (!listCOperation.Success) return OperationErrorBackToIndex(listCOperation.Exception);
                        var cList = new List<SelectListItem>();
                        foreach (var item in listCOperation.Result)
                        {
                            var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name };
                            if (item.Id == vm.CompanyId) listItem.Selected = true;
                            cList.Add(listItem);
                        }
                        ViewBag.Companies = cList;

                        vm = EstablishmentViewModel.Parse(getOperation.Result);

                        Draw("Edit", "fa-edit");
                        return View(vm);
                    }
                    if (!updateOperation.Result)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Message);
                        getOperation = await _bo.ReadAsync((Guid)id);
                        if (!getOperation.Success) return OperationErrorBackToIndex(getOperation.Exception);
                        if (getOperation.Result == null) return RecordNotFound();
                        var listROperation = await _rbo.ListNotDeletedAsync();
                        if (!listROperation.Success) return OperationErrorBackToIndex(listROperation.Exception);
                        var rList = new List<SelectListItem>();
                        foreach (var item in listROperation.Result)
                        {
                            var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name };
                            if (item.Id == vm.RegionId) listItem.Selected = true;
                            rList.Add(listItem);
                        }
                        ViewBag.Regions = rList;

                        var listCOperation = await _cbo.ListNotDeletedAsync();
                        if (!listCOperation.Success) return OperationErrorBackToIndex(listCOperation.Exception);
                        var cList = new List<SelectListItem>();
                        foreach (var item in listCOperation.Result)
                        {
                            var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.Name };
                            if (item.Id == vm.CompanyId) listItem.Selected = true;
                            cList.Add(listItem);
                        }
                        ViewBag.Companies = cList;

                        vm = EstablishmentViewModel.Parse(getOperation.Result);

                        Draw("Edit", "fa-edit");
                        return View(vm);
                    }
                    else return OperationSuccess("The record was successfuly updated");
                }
            }
            return RedirectToAction(nameof(Index));
        }
        public async Task <IActionResult> Edit(Guid id, MenuViewModel vm)
        {
            var listRestOperation = await _rbo.ListNonDeletedAsync();

            if (!listRestOperation.Success)
            {
                return(OperationErrorBackToIndex(listRestOperation.Exception));
            }

            var listMealOperation = await _mbo.ListNonDeletedAsync();

            if (!listMealOperation.Success)
            {
                return(OperationErrorBackToIndex(listMealOperation.Exception));
            }

            var mealList = new List <SelectListItem>();

            foreach (var item in listMealOperation.Result)
            {
                mealList.Add(new SelectListItem()
                {
                    Value = item.Id.ToString(), Text = item.Name
                });
            }

            var restList = new List <SelectListItem>();

            foreach (var item in listRestOperation.Result)
            {
                restList.Add(new SelectListItem()
                {
                    Value = item.Id.ToString(), Text = item.Name
                });
            }

            ViewBag.Meals       = mealList;
            ViewBag.Restaurants = restList;

            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync(id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                if (!vm.CompareToModel(result))
                {
                    result = vm.ToModel(result);
                    var updateOperation = await _bo.UpdateAsync(result);

                    if (!updateOperation.Success)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);
                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Example #25
0
        public async Task <IActionResult> Edit(Guid id, RegionViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync(id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;

                if (!vm.CompareToModel(result))
                {
                    result = vm.ToModel(result);
                    var updateOperation = await _bo.UpdateAsync(result);

                    if (!updateOperation.Success)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);
                        getOperation      = await _bo.ReadAsync((Guid)id);

                        if (!getOperation.Success)
                        {
                            return(OperationErrorBackToIndex(getOperation.Exception));
                        }
                        if (getOperation.Result == null)
                        {
                            return(RecordNotFound());
                        }

                        vm = RegionViewModel.Parse(getOperation.Result);
                        ViewData["Title"] = "Edit Region";
                        var crumbs = GetCrumbs();
                        crumbs.Add(new BreadCrumb()
                        {
                            Action = "Edit", Controller = "Regions", Icon = "fa-search", Text = "Edit"
                        });
                        ViewData["BreadCrumbs"] = crumbs;
                        return(View(vm));
                    }
                    if (!updateOperation.Result)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Message);
                        getOperation      = await _bo.ReadAsync((Guid)id);

                        if (!getOperation.Success)
                        {
                            return(OperationErrorBackToIndex(getOperation.Exception));
                        }
                        if (getOperation.Result == null)
                        {
                            return(RecordNotFound());
                        }

                        vm = RegionViewModel.Parse(getOperation.Result);
                        ViewData["Title"] = "Edit Region";
                        var crumbs = GetCrumbs();
                        crumbs.Add(new BreadCrumb()
                        {
                            Action = "Edit", Controller = "Regions", Icon = "fa-search", Text = "Edit"
                        });
                        ViewData["BreadCrumbs"] = crumbs;
                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(ProductModelViewModel vm)
        {
            var listBOperation = await _bbo.ListNotDeletedAsync();

            if (!listBOperation.Success)
            {
                return(OperationErrorBackToIndex(listBOperation.Exception));
            }

            var listCOperation = await _cbo.ListNotDeletedAsync();

            if (!listCOperation.Success)
            {
                return(OperationErrorBackToIndex(listCOperation.Exception));
            }


            var bList = new List <SelectListItem>();

            foreach (var item in listBOperation.Result)
            {
                bList.Add(new SelectListItem()
                {
                    Value = item.Id.ToString(), Text = item.Name
                });
            }

            var cList = new List <SelectListItem>();

            foreach (var item in listCOperation.Result)
            {
                cList.Add(new SelectListItem()
                {
                    Value = item.Id.ToString(), Text = item.Name
                });
            }
            ViewData["Measure"] = Enum.GetNames(typeof(Measure)).Select(r => new SelectListItem {
                Text = r, Value = r
            });;

            ViewBag.Brands     = bList;
            ViewBag.Categories = cList;

            Draw("Create", "fa-plus");

            if (ModelState.IsValid)
            {
                var model           = vm.ToModel();
                var createOperation = await _bo.CreateAsync(model);

                if (!createOperation.Success)
                {
                    return(OperationErrorBackToIndex(createOperation.Exception));
                }
                if (!createOperation.Result)
                {
                    TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, createOperation.Message);

                    return(View(vm));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly created"));
                }
            }
            return(View(vm));
        }