Beispiel #1
0
        private bool DeletePhotoFromDb(Photo dbPhoto)
        {
            bool result = false;

            try
            {
                _context.Entry <Photo>(dbPhoto).State = EntityState.Deleted;
                _context.SaveChanges();
                result = true;
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(result);
        }
Beispiel #2
0
        public OperationResult DeleteMessage(string userId, int messageId)
        {
            OperationResult result = new OperationResult();

            try
            {
                var message = FindMessage(messageId);

                if (message == null)
                {
                    result.Message = "Message not found!";
                    return(result);
                }

                if (message.SenderId == userId)
                {
                    message.IsSenderDeleted = true;
                }

                if (message.RecipientId == userId)
                {
                    message.IsRecipientDeleted = true;
                }

                if (message.IsSenderDeleted == true && message.IsRecipientDeleted == true)
                {
                    _context.Entry <Message>(message).State = EntityState.Deleted;
                }

                _context.SaveChanges();

                result.IsSuccessful = true;
            }
            catch (System.Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(result);
        }