public async Task <CapitalDataViewModel> CancelCapital(long id)
        {
            Capital capital = capitalRepo.FirstOrDefault(x => x.Id == id);

            capital.Status = CapitalStatus.Cancelled;
            await work.SaveAsync();

            CapitalDataViewModel result = mapper.Map <Capital, CapitalDataViewModel>(capital);

            return(result);
        }
        public CapitalDataViewModel GetCapitalsById(long id)
        {
            Capital capital = capitalRepo.FirstOrDefault(x => x.Id == id);

            if (capital is null)
            {
                return(null);
            }
            CapitalDataViewModel result = mapper.Map <Capital, CapitalDataViewModel>(capital);

            return(result);
        }
Пример #3
0
        public async Task <ActionResult <CapitalDataViewModel> > Create([FromBody] CreateCapitalViewModel request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Wrong request"));
            }
            CapitalDataViewModel capital = await capitalService.CreateCapital(request);

            if (capital is null)
            {
                return(StatusCode(500, "Error occurred"));
            }
            return(Ok(capital));
        }
Пример #4
0
        public ActionResult <CapitalDataViewModel> Get(long id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Wrong request"));
            }
            CapitalDataViewModel capital = capitalService.GetCapitalsById(id);

            if (capital is null)
            {
                return(NotFound("Not found"));
            }
            return(Ok(capital));
        }
Пример #5
0
        public async Task <ActionResult <CapitalDataViewModel> > Cancel(long id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Wrong request"));
            }
            CapitalDataViewModel capital = await capitalService.CancelCapital(id);

            if (capital is null)
            {
                return(StatusCode(500, "Error occurred"));
            }
            return(Ok(capital));
        }
        public async Task <CapitalDataViewModel> UpdateCapital(UpdateCapitalViewModel request)
        {
            Capital capital = capitalRepo.FirstOrDefault(x => x.Id == request.Id);

            if (capital is null)
            {
                return(null);
            }

            capital = mapper.Map <UpdateCapitalViewModel, Capital>(request);
            capitalRepo.Update(capital);
            await work.SaveAsync();

            CapitalDataViewModel result = mapper.Map <Capital, CapitalDataViewModel>(capital);

            return(result);
        }
        public async Task <CapitalDataViewModel> CreateCapital(CreateCapitalViewModel request)
        {
            DappUser user = userRepo.FirstOrDefault(x => x.PublicAddress == request.CreatorPublicAddress);

            if (user is null)
            {
                return(null);
            }
            Capital capital = mapper.Map <CreateCapitalViewModel, Capital>(request);

            capital.Creator      = user;
            capital.CreationDate = DateTime.Today;
            capital.Status       = CapitalStatus.Finished;
            capitalRepo.Add(capital);
            await work.SaveAsync();

            CapitalDataViewModel result = mapper.Map <Capital, CapitalDataViewModel>(capital);

            return(result);
        }