Пример #1
0
        public async Task <IActionResult> OnPostNewContribution(SIContribution_Dto contrib, string categoryName)
        {
            try
            {
                contrib.TenantId     = CurrentUser.TenantId;
                contrib.SICategoryId = ContribCatRepo.First(x => x.Title == categoryName).Id;
                var added = await ContribsRepo.InsertAsync(ObjectMapper.Map <SIContribution_Dto, SIContribution>(contrib));

                return(new JsonResult(added));
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
        }
Пример #2
0
        public async Task <IActionResult> OnPostContribution(SIContribution_Dto contrib, string categoryName)
        {
            try
            {
                var toUpdate = await ContribsRepo.FindAsync(x => x.Id == contrib.Id);

                toUpdate.Title        = contrib.Title;
                toUpdate.IsPercentage = contrib.IsPercentage;
                toUpdate.Value        = contrib.Value;
                toUpdate.SICategoryId = ContribCatRepo.First(x => x.Title == categoryName).Id;
                toUpdate.SICategory   = null;
                var updated = await ContribsRepo.UpdateAsync(toUpdate);

                return(new JsonResult(updated));
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
        }