public async Task <IActionResult> UpdateDava([FromBody] DavaViewModel davaVm)
        {
            try
            {
                var dava = _davaRepository.GetDava(davaVm.Id);

                if (dava != null)
                {
                    var avukat = await _userManager.FindByIdAsync(davaVm.AvukatId);

                    var muvekkil = await _userManager.FindByIdAsync(davaVm.MuvekkilId);

                    var davaState = _davaStateRepository.GetDavaState(davaVm.DavaStateId);

                    dava.Name      = davaVm.Name;
                    dava.Avukat    = avukat;
                    dava.Muvekkil  = muvekkil;
                    dava.DavaState = davaState;

                    _davaRepository.UpdateDava(dava);
                    return(Ok(davaVm));
                }
                return(BadRequest("Böyle bir dava bulunamadı"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> AddDocument([FromForm] DocumentViewModel model, IFormFile file)
        {
            try
            {
                var user = await _userManager.FindByEmailAsync(model.OwnerUserName);

                var dava     = _davaRepository.GetDava(model.DavaId);
                var document = new Document();
                if (user == null)
                {
                    throw new Exception("Kullanıcı bulunamadı!");
                }
                if (file == null)
                {
                    throw new Exception("Dosya Bulunamadı!");
                }
                if (dava == null)
                {
                    throw new Exception("Dosya ile ilişkilendirilecek dava bulunamadı!");
                }
                var filePath = model.DavaId.ToString() + "-" + model.Date.ToShortDateString() + "-" + Path.GetRandomFileName() + file.FileName;

                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\documents", filePath);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    file.CopyToAsync(stream).Wait();
                }
                document.Date        = model.Date;
                document.Description = model.Description;
                document.FileName    = file.FileName;

                document.Dava     = dava;
                document.Owner    = user;
                document.FilePath = filePath;
                document.IsActive = true;

                var doc   = _documentRepository.AddDocument(document);
                var docVM = _mapper.Map <DocumentViewModel>(doc);


                return(Ok(docVM));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> AddMasraf([FromBody] MasrafViewModel model)
        {
            try
            {
                var user = await _userManager.FindByEmailAsync(model.OwnerUserName);

                var dava   = _davaRepository.GetDava(model.DavaId);
                var masraf = new Masraf {
                    Owner = user, Amount = model.Amount, Dava = dava, Date = model.Date.Date, Description = model.Description
                };
                var newMasraf = _masrafRepository.AddMasraf(masraf);
                var marafvm   = _mapper.Map <MasrafViewModel>(newMasraf);
                return(Ok(marafvm));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> AddMessage([FromBody] MessageViewModel model)
        {
            var user = await _userManager.FindByEmailAsync(model.OwnerUserName);

            if (user != null)
            {
                var message = new Message();
                var dava    = _davaRepository.GetDava(model.DavaId);
                if (dava != null)
                {
                    message.Dava     = dava;
                    message.Owner    = user;
                    message.Text     = model.Text;
                    message.Date     = model.Date.Date;
                    message.IsActive = true;
                    var mes   = _messageRepository.AddMessage(message);
                    var mesVM = _mapper.Map <MessageViewModel>(mes);
                    return(Ok(mesVM));
                }
                return(BadRequest("Dava bulunmadığı için mesaj eklenemedi"));
            }
            return(BadRequest("Kullanıcı bulunmadığı için mesaj eklenemedi"));
        }