Пример #1
0
        public void TestUpdateInterestPointAsync()
        {
            BoraNowSeeder.Seed();

            var ipbo    = new InterestPointBusinessObject();
            var resList = ipbo.List();
            var item    = resList.Result.FirstOrDefault();

            var cbo = new CompanyBusinessObject();
            var pbo = new ProfileBusinessObject();

            var profile = new Profile("II", "AA");

            pbo.Create(profile);

            var company = new Company("kfc", "you", "9111222", "11111", profile.Id);

            cbo.Create(company);

            var interestPoint = new InterestPoint("a", "b", "c", "d", "e", "f", "g", true, true, company.Id);

            item.Name         = interestPoint.Name;
            item.Address      = interestPoint.Address;
            item.ClosingDays  = interestPoint.ClosingDays;
            item.ClosingHours = interestPoint.ClosingHours;
            item.Description  = interestPoint.Description;
            item.OpeningHours = interestPoint.OpeningHours;
            item.PhotoPath    = interestPoint.PhotoPath;
            item.CovidSafe    = interestPoint.CovidSafe;
            item.Status       = interestPoint.Status;
            item.CompanyId    = interestPoint.CompanyId;

            var resUpdate = ipbo.UpdateAsync(item).Result;

            resList = ipbo.ListAsync().Result;

            Assert.IsTrue(resUpdate.Success && resList.Success && resList.Result.First().Name == interestPoint.Name &&
                          resList.Result.First().Address == interestPoint.Address &&
                          resList.Result.First().ClosingHours == interestPoint.ClosingHours &&
                          resList.Result.First().Description == interestPoint.Description &&
                          resList.Result.First().ClosingDays == interestPoint.ClosingDays &&
                          resList.Result.First().OpeningHours == interestPoint.OpeningHours &&
                          resList.Result.First().PhotoPath == interestPoint.PhotoPath &&
                          resList.Result.First().CovidSafe == interestPoint.CovidSafe &&
                          resList.Result.First().Status == interestPoint.Status &&
                          resList.Result.First().CompanyId == interestPoint.CompanyId);
        }
        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)));
        }