public async Task <BarangResponse> GetHargaOTRTypeBarangID(BarangRequest request) { BarangResponse response = new BarangResponse(); try { Barang brg = await dep.GetHargaOTRTypeBarangID(request.TypeBarangId); response.Model = new BarangViewModel() { Id = brg.Id, Name = brg.Name, TypeBarangId = brg.TypeBarangId, HargaOtr = brg.HargaOtr }; response.IsSuccess = true; response.Message = "Success"; } catch (Exception ex) { log.Error(ex); response.IsSuccess = false; response.Message = ex.ToString(); } return(response); }
public async Task <BarangResponse> GetHargaOTR(BarangRequest request) { BarangResponse response = new BarangResponse(); try { Barang model = new Barang(); model.WarnaId = request.WarnaId; model.TypeBarangId = request.TypeBarangId; var result = await dep.GetHargaOTR(model); if (result != null) { response.Model.Id = result.Id; response.Model.HargaOtr = result.HargaOtr; response.IsSuccess = true; response.Message = "Load Harga OTR Success"; } else { response.Message = "Data dengan Warna dan Type tersebut Tidak ada"; response.IsSuccess = false; } } catch (Exception ex) { log.Error(ex); response.Message = ex.ToString(); response.IsSuccess = false; } return(response); }
public IActionResult GetAllBidsById([FromQuery] BarangRequest request) { long Id = request.ID;//Convert.ToInt32(HttpContext.Request.Query["id"]); int start = Convert.ToInt32(HttpContext.Request.Query["start"]); int limit = Convert.ToInt32(HttpContext.Request.Query["limit"]); int max = Convert.ToInt32(HttpContext.Request.Query["max"]); if (Id < 1) { return(BadRequest()); } try { BarangResponse post = facade.GetAllBidsById(request); post.IsSuccess = true; post.Message = "Success"; if (post == null) { return(NotFound()); } return(Ok(post)); } catch (Exception ex) { return(BadRequest(ex)); } }
public async Task <BarangResponse> GetBarangDetail(int id) { BarangResponse resp = new BarangResponse(); BarangRequest req = new BarangRequest(); req.ID = id; resp.CarDetail = await dep.GetBarangDetail(id); resp.RelatedProducts = dep.GetRelatedProducts(id); resp.SP_GetPhotoAndWarnaByBarangIDS = await dep.GetPhotoAndWarnaByID(req); resp.ListModelForDetail = await dep.GetTypeBarangByBarangID(req); // Update Jumlah Klik Barang b = await dep.GetBarang(id); if (b != null) { if (!b.JumlahKlik.HasValue || b.JumlahKlik < 1) { b.JumlahKlik = 1; b.Modified = DateTime.Now; b.ModifiedBy = "System"; } if (await dep.UpdatePost(b)) { } } resp.IsSuccess = true; resp.Message = "Success"; return(resp); }
public BarangResponse GetAllBidsById(BarangRequest req) { BarangResponse resp = new BarangResponse(); resp.ListBids = dep.GetAllBidsById(req); return(resp); }
public async Task <IActionResult> UpdatePost([FromBody] BarangRequest request) { if (ModelState.IsValid) { try { BarangResponse response = new BarangResponse(); string bearer = Request.HttpContext.Request.Headers["Authorization"]; string token = bearer.Substring("Bearer ".Length).Trim(); string username = string.Empty; if (string.IsNullOrEmpty(token)) { response.IsSuccess = false; response.Message = "You don't have access."; return(BadRequest(response)); } username = sec.ValidateToken(token); if (username == null) { Response.HttpContext.Response.Cookies.Append("access_token", "", new CookieOptions() { Expires = DateTime.Now.AddDays(-1) }); response.IsSuccess = false; response.Message = "Your session was expired, please re-login."; return(BadRequest(response)); } var result = await facade.UpdatePost(request, username); return(Ok(result)); } catch (Exception ex) { if (ex.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException") { return(NotFound()); } return(BadRequest()); } } return(BadRequest()); }
public async Task <IActionResult> AddPost([FromBody] BarangRequest model) { BarangResponse result = new BarangResponse(); if (ModelState.IsValid) { try { string bearer = Request.HttpContext.Request.Headers["Authorization"]; string token = bearer.Substring("Bearer ".Length).Trim(); string username = string.Empty; if (string.IsNullOrEmpty(token)) { result.IsSuccess = false; result.Message = "You don't have access."; return(BadRequest(result)); } username = sec.ValidateToken(token); if (username == null) { Response.HttpContext.Response.Cookies.Append("access_token", "", new CookieOptions() { Expires = DateTime.Now.AddDays(-1) }); result.IsSuccess = false; result.Message = "Your session was expired, please re-login."; return(BadRequest(result)); } if (model.ID > 0) { result = await facade.UpdatePost(model, username); } else { result = await facade.AddPost(model, username); } return(Ok(result)); } catch (Exception) { return(BadRequest()); } } return(BadRequest()); }
public async Task <BarangResponse> UpdatePost(BarangRequest request, string username) { BarangResponse response = new BarangResponse(); try { TypeBarangRequest typeRequest = new TypeBarangRequest(); typeRequest.ID = request.TypeBarangId; var getTYpe = da_type.GetPost(typeRequest).Result; Barang model = new Barang(); model.Id = request.ID; model.HargaOtr = request.HargaOtr; model.Name = getTYpe.Model.Name; model.WarnaId = request.WarnaId; model.TypeBarangId = request.TypeBarangId; model.KotaId = request.KotaID.Value; //model.PhotoPath = request.PhotoPath; model.Year = request.Year.Value; model.Modified = DateTime.Now; model.ModifiedBy = username; bool result = await dep.UpdatePost(model); if (result) { response.Message = "Data Already Saved"; response.IsSuccess = true; } else { response.Message = "Update Failed"; response.IsSuccess = false; } } catch (Exception ex) { log.Error(ex); response.Message = ex.ToString(); response.IsSuccess = false; } return(response); }
public List <CarBids> GetAllBidsById(BarangRequest req) { if (db != null) { try { int result = 0; return(db.Set <CarBids>().FromSql("EXEC sp_GetAllBidsByID_With_Paging {0},{1},{2},{3},{4},{5},{6}", req.ID, req.start, req.limit, null, null, req.max, result).AsNoTracking().ToList()); } catch (Exception ex) { throw ex; } } return(null); }
public async Task <IActionResult> GetHargaOTRTypeBarangID([FromBody] BarangRequest request) { BarangResponse result = new BarangResponse(); if (ModelState.IsValid) { try { result = await facade.GetHargaOTRTypeBarangID(request); return(Ok(result)); } catch (Exception) { return(BadRequest()); } } return(BadRequest()); }
public async Task <BarangResponse> UpdateImageBarang(BarangRequest request, string username) { BarangResponse response = new BarangResponse(); try { Barang model = new Barang() { Id = request.ID }; List <Barang> ListBarang = await dep.GetAllBarangSameTypeAndKota(model); foreach (Barang brg in ListBarang) { brg.PhotoPath = request.PhotoPath; brg.Modified = DateTime.Now; brg.ModifiedBy = username; } bool result = await dep.UpdateMany(ListBarang); if (result) { response.Message = "Data Already Saved"; response.IsSuccess = true; } else { response.Message = "Update Failed"; response.IsSuccess = false; } } catch (Exception ex) { log.Error(ex); response.Message = ex.ToString(); response.IsSuccess = false; } return(response); }
public async Task <BarangResponse> AddPost(BarangRequest request, string email) { BarangResponse response = new BarangResponse(); try { TypeBarangRequest typeRequest = new TypeBarangRequest(); typeRequest.ID = request.TypeBarangId; var getTYpe = da_type.GetPost(typeRequest).Result; Barang model = new Barang(); model.HargaOtr = request.HargaOtr; model.Name = getTYpe.Model.Name; model.WarnaId = request.WarnaId; model.PhotoPath = request.PhotoPath; model.TypeBarangId = request.TypeBarangId; model.Created = DateTime.Now; model.CreatedBy = email; model.RowStatus = true; model.KotaId = request.KotaID.Value; var postId = await dep.AddPost(model); if (postId > 0) { response.Message = "Data Already Saved"; response.IsSuccess = true; } else { response.Message = "Save Failed"; response.IsSuccess = false; } } catch (Exception ex) { response.Message = ex.ToString(); response.IsSuccess = false; } return(response); }
public async Task <BarangResponse> GetBarangByHomeParameter(BarangRequest request) { BarangResponse response = new BarangResponse(); try { response.sp_GetBarangByHomeParameters = await dep.GetBarangByHomeParameter(request); response.SP_GetBarangByHomeParameterCount = await dep.GetBarangByHomeParameterCount(request); response.Total = response.SP_GetBarangByHomeParameterCount.total; response.IsSuccess = true; response.Message = "Success"; } catch (Exception ex) { response.IsSuccess = false; response.Message = ex.ToString(); } return(response); }
public async Task <IActionResult> GetHargaOTR([FromBody] BarangRequest request) { if (ModelState.IsValid) { try { var result = await facade.GetHargaOTR(request); return(Ok(result)); } catch (Exception ex) { if (ex.GetType().FullName == "Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException") { return(NotFound()); } return(BadRequest()); } } return(BadRequest()); }
public async Task <List <SP_GetTypeBarangByBarangID> > GetTypeBarangByBarangID(BarangRequest request) { try { return(await db.Set <SP_GetTypeBarangByBarangID>().FromSql("EXEC sp_GetTypeBarangByBarangID {0}", request.ID).AsNoTracking().ToListAsync()); } catch (Exception ex) { throw ex; } }
public async Task <SP_GetBarangByHomeParameterCount> GetBarangByHomeParameterCount(BarangRequest request) { try { return(await db.Set <SP_GetBarangByHomeParameterCount>().FromSql("EXEC SP_GetBarangByHomeParameterCount {0},{1},{2},{3},{4},{5},{6}", request.KotaID, request.MerkID, request.ModelBarangID, request.TypeID, request.Year, request.start, request.limit).AsNoTracking().FirstOrDefaultAsync()); } catch (Exception ex) { throw ex; } }