public async Task <ServiceRespone> PostBinhLuan(BinhLuan binhLuan) { ServiceRespone res = new ServiceRespone(); binhLuan.ThoiGian = DateTime.Now; _context.BinhLuans.Add(binhLuan); res.Success = true; res.Message = "Thành Công!"; try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (BinhLuanExists(binhLuan.TaiKhoan)) { res.Message = "Bình luận tiếp"; } else { res.Message = "Có lỗi!"; res.Success = false; throw; } } return(res); }
public async Task <ServiceRespone> PostTaiKhoan(TaiKhoan taiKhoan) { ServiceRespone res = new ServiceRespone(); if (taiKhoan.TaiKhoan1.Trim() == "" || taiKhoan.MatKhau.Trim() == "") { res.Message = "Vui lòng nhập các trường bắt buộc"; res.Success = false; return(res); } var taikhoanDB = _context.TaiKhoans.FirstOrDefault(x => x.TaiKhoan1 == taiKhoan.TaiKhoan1); if (taikhoanDB != null) { res.Message = "Tên đăng nhập này đã được sử dụng"; res.Success = false; res.ErrorCode = 1; return(res); } taiKhoan.LoaiTk = 0; _context.TaiKhoans.Add(taiKhoan); await _context.SaveChangesAsync(); res.Success = true; return(res); }
public ServiceRespone GetTaiKhoan(string taikhoan, string matkhau) { ServiceRespone res = new ServiceRespone(); var taiKhoanDB = _context.TaiKhoans.Where(s => s.TaiKhoan1 == taikhoan && s.MatKhau == matkhau).FirstOrDefault(); if (taiKhoanDB == null) { res.Message = "Sai tên đăng nhập hoặc mật khẩu"; res.Success = false; return(res); } if (taiKhoanDB.LoaiTk == 1) { res.Success = true; res.Type = 1; res.Data = taiKhoanDB; } else { res.Success = true; res.Type = 0; res.Data = taiKhoanDB; } return(res); }
public async Task <ServiceRespone> PostMuaVip(MuaVip muaVip) { ServiceRespone res = new ServiceRespone(); muaVip.NgayMua = DateTime.Now; _context.MuaVips.Add(muaVip); res.Success = true; res.Message = "Đã Đăng Ký Gói!"; try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (MuaVipExists(muaVip.TaiKhoan)) { res.Message = "Tài khoản nạp thêm hạn"; } else { res.Message = "Có lỗi!"; res.Success = false; throw; } } return(res); }
public IHttpActionResult MapServiceToHttpResponse(ServiceRespone response) { switch (response.ResponseCode) { case ResponeCode.NotFound: { return(NotFound()); } case ResponeCode.DbError: { return(BadRequest(response.ErrorMessage)); } case ResponeCode.BadRequest: { return(BadRequest(response.ErrorMessage)); } case ResponeCode.Success: { return(Ok(response.Value)); } case ResponeCode.DbRecordCreated: { return(Created(Request.RequestUri, response.Value)); } case ResponeCode.DbRecordDeleted: { return(StatusCode(HttpStatusCode.NoContent)); } case ResponeCode.DbRecordUpdated: { return(StatusCode(HttpStatusCode.NoContent)); } default: { return(Ok(response.Value)); } } }
public async Task <ServiceRespone> GetBinhLuan(string id) { ServiceRespone res = new ServiceRespone(); var binhluan = await _context.BinhLuans.Where(x => x.MaPhim.Equals(id)).ToListAsync(); res.Data = binhluan; res.Message = "Thành Công"; res.Success = true; if (binhluan == null) { res.Message = "Có Lỗi"; res.Success = false; return(res); } return(res); }
public ServiceRespone PosterFilm(IFormFile files, [FromServices] IHostingEnvironment oHostingEnvironment) { ServiceRespone res = new ServiceRespone(); if (files.Length > 0) { string url = $"{oHostingEnvironment.WebRootPath}\\Upload-img\\{files.FileName}"; using (FileStream fileStream = System.IO.File.Create(url)) { files.CopyTo(fileStream); fileStream.Flush(); } res.Success = true; res.Data = files; } else { res.Success = false; } return(res); }