Exemplo n.º 1
0
        public async Task <IActionResult> Update([FromBody] StaffRecordViewModel vm)
        {
            var getResult = await _bo.ReadAsync(vm.Id);

            if (!getResult.Success)
            {
                return(InternalServerError(getResult.Exception));
            }
            var item = getResult.Result;

            if (item == null)
            {
                return(NotFound());
            }
            if (vm.CompareToModel(item))
            {
                return(NotModified());
            }
            item = vm.ToModel(item);
            var updateResult = await _bo.UpdateAsync(item);

            if (!updateResult.Success)
            {
                return(InternalServerError(updateResult.Exception));
            }
            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(Guid id, StaffRecordViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync(id);

                if (!getOperation.Success)
                {
                    return(View("Error", new ErrorViewModel()
                    {
                        RequestId = getOperation.Exception.Message
                    }));
                }
                if (getOperation.Result == null)
                {
                    return(NotFound());
                }
                var result = getOperation.Result;
                if (!vm.CompareToModel(result))
                {
                    result = vm.ToModel(result);
                    var updateOperation = await _bo.UpdateAsync(result);

                    if (!updateOperation.Success)
                    {
                        return(View("Error", new ErrorViewModel()
                        {
                            RequestId = updateOperation.Exception.Message
                        }));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 3
0
        public void TestUpdateStaffRecordAsync()
        {
            RestaurantSeeder.SeedCountries();
            var bo      = new StaffRecordBusinessObject();
            var resList = bo.ListAsync().Result;
            var item    = resList.Result.FirstOrDefault();

            item.BeginDate = DateTime.Parse("2020/06/05");
            var resUpdate = bo.UpdateAsync(item).Result;

            resList = bo.ListUnDeletedAsync().Result;
            Assert.IsTrue(resList.Success && resUpdate.Success && resList.Result.First().BeginDate == DateTime.Parse("2020/06/05"));
        }
Exemplo n.º 4
0
        public void TestUpdateStaffRecordAsync()
        {
            RestaurantSeeder.Seed();
            var bo      = new StaffRecordBusinessObject();
            var resList = bo.ListAsync().Result;
            var item    = resList.Result.FirstOrDefault();
            var now     = DateTime.Now;

            item.BeginDate = now;
            var resUpdate = bo.UpdateAsync(item).Result;

            resList = bo.ListNonDeletedAsync().Result;
            Assert.IsTrue(resList.Success && resUpdate.Success && resList.Result.First().BeginDate == now);
        }
Exemplo n.º 5
0
        public void TestUpdateStaffRecordAsync()
        {
            ContextSeeders.Seed();
            var srbo    = new StaffRecordBusinessObject();
            var resList = srbo.List();
            var item    = resList.Result.FirstOrDefault();

            var pbo  = new PersonBusinessObject();
            var rbo  = new RestaurantBusinessObject();
            var lubo = new LennyouseUserBusinessObject();

            var _lennyouseUser = new LennyouseUser(Guid.NewGuid());

            lubo.Create(_lennyouseUser);

            var _person = new Person(3654324444, 0000000, "Marco", "Figueirnha", DateTime.UtcNow, _lennyouseUser.Id);

            pbo.Create(_person);

            var _restaurant = new Restaurant("Tasca da Lua", "Bairro Alto 2", "12h", "00h", "Mondays", 7);

            rbo.Create(_restaurant);


            var _newStaffRecord = new StaffRecord(DateTime.UtcNow, DateTime.UtcNow, _person.Id, _restaurant.Id);

            item.BeginDate    = _newStaffRecord.BeginDate;
            item.EndDate      = _newStaffRecord.EndDate;
            item.PersonId     = _newStaffRecord.PersonId;
            item.RestaurantId = _newStaffRecord.RestaurantId;

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

            resList = srbo.ListAsync().Result;

            Assert.IsTrue(resList.Success && resUpdate.Success &&
                          resList.Result.First().BeginDate == _newStaffRecord.BeginDate &&
                          resList.Result.First().EndDate == _newStaffRecord.EndDate &&
                          resList.Result.First().PersonId == _newStaffRecord.PersonId &&
                          resList.Result.First().RestaurantId == _newStaffRecord.RestaurantId
                          );
        }