public async Task <ActionResult> Create(DeTaiNghienCuuViewModel vmodel) { IEnumerable <DeTaiNghienCuu> list = await _service.GetAll(); if (list.Count() != 0) { DeTaiNghienCuu LastE = list.OrderBy(x => x.Id).LastOrDefault(); vmodel.Id = _service.KhoiTaoMa(LastE); } else { vmodel.Id = long.Parse(DateTime.Now.Year.ToString() + "001"); } var model = new DeTaiNghienCuu() { Id = vmodel.Id, TenDeTai = vmodel.TenDeTai, MoTa = vmodel.MoTa, IdgiangVien = long.Parse(User.Identity.Name), NgayLap = DateTime.Now, TinhTrangDangKy = (int)StatusDangKyDeTai.Con, TinhTrangDeTai = (int)StatusDeTai.MoiTao, Loai = LoaiDeTai.CoSan }; if (await UpLoadFile(vmodel.Files, model) == false) { return(Json(new { status = false, mess = MessageResult.UpLoadFileFail })); } try { var isAuthorize = await _authorizationService.AuthorizeAsync(User, model, DeTaiNghienCuuOperation.Create); if (!isAuthorize.Succeeded) { return(Ok(new { status = false, toastr = MessageResult.AccessDenied })); } await _service.Add(model); return(Json(new { status = true, create = true, data = new { NgayLap = DateTime.Now.ToString("dd/MM/yyyy"), Id = vmodel.Id, TenTep = model.TenTep }, mess = MessageResult.CreateSuccess })); } catch (Exception e) { return(Json(new { status = false, mess = e.ToString() })); } }
public async Task <ActionResult> DeXuatDeTai(DeTaiNghienCuuViewModel vmodel) { var SV = await _serviceSV.GetById(long.Parse(User.Identity.Name)); if (SV == null) { return(Ok(new { status = false, mess = MessageResult.NotFoundSV })); } if (vmodel.IdgiangVien == 0) { vmodel.IdgiangVien = null; } //Update DeTai if (vmodel.Id > 0) { var DeTai = await _service.GetById(vmodel.Id); DeTai.IdgiangVien = vmodel.IdgiangVien; DeTai.MoTa = vmodel.MoTa; DeTai.TenDeTai = vmodel.TenDeTai; if (await UpLoadFile(vmodel.Files, DeTai) == false) { return(Json(new { status = false, mess = MessageResult.UpLoadFileFail })); } await _service.Update(DeTai); return(Ok(new { status = true, mess = MessageResult.UpdateSuccess })); } //Kiểm tra SV đã có đề tài? var nhomSV = SV.NhomSinhVien.SingleOrDefault(x => x.IdnhomNavigation.Status == (int)BaseStatus.Active); if (nhomSV != null) { return(Ok(new { status = false, mess = MessageResult.ExistDeTai })); } IEnumerable <DeTaiNghienCuu> list = await _service.GetAll(); if (list.Count() != 0) { DeTaiNghienCuu LastE = list.OrderBy(x => x.Id).LastOrDefault(); vmodel.Id = _service.KhoiTaoMa(LastE); } else { vmodel.Id = long.Parse(DateTime.Now.Year.ToString() + "001"); } var model = new DeTaiNghienCuu() { Id = vmodel.Id, TenDeTai = vmodel.TenDeTai, MoTa = vmodel.MoTa, NgayDangKy = DateTime.Now, IdNguoiDangKy = long.Parse(User.Identity.Name), IdgiangVien = vmodel.IdgiangVien, NgayLap = DateTime.Now, TinhTrangDangKy = (int)StatusDangKyDeTai.Het, TinhTrangDeTai = (int)StatusDeTai.DaDangKy, Loai = LoaiDeTai.DeXuat }; if (await UpLoadFile(vmodel.Files, model) == false) { return(Json(new { status = false, mess = MessageResult.UpLoadFileFail })); } try { Nhom nhom = new Nhom(); await _serviceNhom.Add(nhom); NhomSinhVien nhomSinhVien = new NhomSinhVien { Idnhom = nhom.Id, IdsinhVien = SV.Mssv }; model.NhomSinhVien.Add(nhomSinhVien); await _service.Add(model); return(Json(new { status = true, create = true, data = model, mess = MessageResult.CreateSuccess })); } catch { return(Json(new { status = false, mess = MessageResult.Fail })); } }