Example #1
0
        UpdateCommentAsync(CommentDTOAdministration comment, CancellationToken cancellationToken = default(CancellationToken))
        {
            comment.Update = DateTime.UtcNow;
            Comment commentForUpdate = _mapper.Map <Comment>(comment);

            _db.Entry(commentForUpdate).Property(c => c.Title).IsModified = true;
            _db.Entry(commentForUpdate).Property(c => c.Text).IsModified  = true;

            _db.Entry(commentForUpdate).Property(c => c.Update).IsModified = true;

            try
            {
                await _db.SaveChangesAsync(cancellationToken);

                return((Result <CommentDTOAdministration>) Result <CommentDTOAdministration>
                       .Ok(comment));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return((Result <CommentDTOAdministration>) Result <CommentDTOAdministration>
                       .Fail <CommentDTOAdministration>($"Cannot update model. {ex.Message}"));
            }
            catch (DbUpdateException ex)
            {
                return((Result <CommentDTOAdministration>) Result <CommentDTOAdministration>
                       .Fail <CommentDTOAdministration>($"Cannot update model. {ex.Message}"));
            }
        }
        public async Task <IActionResult> PutApartment(int id, Apartment apartment)
        {
            if (id != apartment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(apartment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ApartmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        DeleteOrderByIdAsync(string orderId, string customerId, CancellationToken cancellationToken = default(CancellationToken))
        {
            Guid id    = Guid.Parse(orderId);
            Guid cusId = Guid.Parse(customerId);

            var isOrder = await _db.Orders
                          .Where(_ => _.Id == id)
                          .Where(_ => _.CustomerId == cusId)
                          .IgnoreQueryFilters().AnyAsync();

            if (!isOrder)
            {
                return(await Task.FromResult(Result.NotOk("Order was not found or you are not customer")));
            }

            _db.Entry(new Order()
            {
                Id = id
            }).State = EntityState.Deleted;

            try
            {
                await _db.SaveChangesAsync(cancellationToken);

                return(await Task.FromResult(Result.Ok()));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(await Task.FromResult(Result.Fail($"Cannot delete Order. {ex.Message}")));
            }
            catch (DbUpdateException ex)
            {
                return(await Task.FromResult(Result.Fail($"Cannot delete Order. {ex.InnerException.Message}")));
            }
        }
Example #4
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }
            var hashed = GetHashedPassword(user.Password, out byte[] salt);

            user.Password     = hashed;
            user.PasswordSalt = salt;

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
 public void Update(Tenant tenant)
 {
     using (var context = new ApartmentContext())
     {
         context.Entry(tenant).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void Update(Reservation reservation)
 {
     using (var context = new ApartmentContext())
     {
         context.Entry(reservation).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #7
0
        UpdateApartmentAsync(ApartmentView apartment, CancellationToken cancellationToken = default(CancellationToken))
        {
            apartment.Address.CountryId = apartment.Country.Id;

            Apartment apartmentForUpdate = _mapper.Map <Apartment>(apartment.Apartment);
            Address   addressForUpdate   = _mapper.Map <Address>(apartment.Address);

            apartmentForUpdate.Update = DateTime.UtcNow;

            _db.Entry(apartmentForUpdate).Property(c => c.Title).IsModified         = true;
            _db.Entry(apartmentForUpdate).Property(c => c.Text).IsModified          = true;
            _db.Entry(apartmentForUpdate).Property(c => c.Area).IsModified          = true;
            _db.Entry(apartmentForUpdate).Property(c => c.IsOpen).IsModified        = true;
            _db.Entry(apartmentForUpdate).Property(c => c.Price).IsModified         = true;
            _db.Entry(apartmentForUpdate).Property(c => c.NumberOfRooms).IsModified = true;
            _db.Entry(apartmentForUpdate).Property(c => c.Update).IsModified        = true;

            _db.Entry(addressForUpdate).Property(c => c.CountryId).IsModified         = true;
            _db.Entry(addressForUpdate).Property(c => c.City).IsModified              = true;
            _db.Entry(addressForUpdate).Property(c => c.Street).IsModified            = true;
            _db.Entry(addressForUpdate).Property(c => c.Home).IsModified              = true;
            _db.Entry(addressForUpdate).Property(c => c.NumberOfApartment).IsModified = true;

            try
            {
                await _db.SaveChangesAsync(cancellationToken);

                return((Result <ApartmentView>) Result <ApartmentView>
                       .Ok(apartment));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return((Result <ApartmentView>) Result <ApartmentView>
                       .Fail <ApartmentView>($"Cannot update model. {ex.Message}"));
            }
            catch (DbUpdateException ex)
            {
                return((Result <ApartmentView>) Result <ApartmentView>
                       .Fail <ApartmentView>($"Cannot update model. {ex.Message}"));
            }
        }