Example #1
0
        public async Task <IActionResult> Put(string tenantId, DateTime date, [FromBody] WishDay noteDay)
        {
            _logger.LogInformation($"Beginning POST: {noteDay.Date}");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _logger.LogInformation("Posting new Habit with name {habitName}", noteDay.Date);
            var result = await _service.SaveAsync(tenantId, noteDay);

            if (result.Succeeded)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Example #2
0
        public async Task <ActionResult> SaveAsync(string tenantId, WishDay wishDay)
        {
            try
            {
                wishDay.TenantId = tenantId;
                var item = _dbContext.WishDaysRepository.Query(l => l.Id == wishDay.Id).FirstOrDefault();
                if (item != null)
                {
                    _dbContext.WishDaysRepository.Update(item);
                }
                else
                {
                    _dbContext.WishDaysRepository.Insert(wishDay);
                }
                await _dbContext.SaveChangesAsync();

                return(ActionResult.Success(wishDay));
            }
            catch (Exception ex)
            {
                return(ActionResult.Failed());
            }
        }
Example #3
0
        public async Task<ActionResult> SaveAsync(string tenantId, WishDay wishDay)
        {
            try
            {
                wishDay.TenantId = tenantId;
                var item = _dbContext.WishDaysRepository.Query(l => l.Id == wishDay.Id).FirstOrDefault();
                if (item != null)
                {
                    _dbContext.WishDaysRepository.Update(item);
                }
                else
                {
                    _dbContext.WishDaysRepository.Insert(wishDay);
                }
                await _dbContext.SaveChangesAsync();

                return ActionResult.Success(wishDay);
            }
            catch (Exception ex)
            {
                return ActionResult.Failed();
            }
        }