public async Task <NegoBarangResponse> SubmitBid(NegoBarangRequest req) { NegoBarangResponse response = new NegoBarangResponse(); NegoBarang model = new NegoBarang(); UserProfile userProfile = await IAuth.GetUserProfileByEmail(req.UserName); try { if (req.ID > 0) { model.Id = req.ID; model.UserProfileId = userProfile.Id; model.BarangId = req.BarangID; model.Harga = req.Harga; model.TypePenawaran = req.TypePenawaran = "BID"; model.Created = DateTime.Now; model.CreatedBy = req.UserName; model.RowStatus = true; if (await dep.UpdatePost(model) > 0) { response.IsSuccess = true; response.Message = "Update Success"; } else { response.IsSuccess = false; response.Message = "Update Failed"; } } else { model.UserProfileId = userProfile.Id; model.BarangId = req.BarangID; model.TypePenawaran = req.TypePenawaran = "BID"; model.Created = DateTime.Now; model.CreatedBy = req.UserName; model.RowStatus = true; model.Harga = req.Harga; if (await dep.AddPost(model) > 0) { response.IsSuccess = true; response.Message = "Data Already Saved"; } else { response.IsSuccess = false; response.Message = "Save Failed"; } } } catch (Exception ex) { log.Error(ex); response.IsSuccess = false; response.Message = ex.Message.ToString(); } //return await dep.AddPost(req); return(response); }
public async Task <TransactionResponse> SubmitSell(long id, long nominal, string username) { TransactionResponse response = new TransactionResponse(); NegoBarang nego = new NegoBarang() { BarangId = id, TypePenawaran = "bid", Harga = nominal }; NegoBarang ResultNego = await INego.GetNegoBarang(nego); UserProfile usrSell = await IAuth.GetUserProfileByEmail(username); UserDetail userDetail = await IAuth.GetUserDetailByID(usrSell.Id); if (userDetail == null) { response.IsSuccess = false; response.Message = "Pastikan Anda adalah Seller yang terverifikasi"; return(response); } if (userDetail.Description == null || userDetail.Description.ToLower() != "seller") { response.IsSuccess = false; response.Message = "Pastikan Anda adalah Seller yang terverifikasi"; return(response); } if (ResultNego == null) { response.Message = "Failed When Save Transaction"; response.IsSuccess = false; return(response); } Transaction tran = new Transaction() { BuyerId = ResultNego.UserProfileId, SellerId = usrSell.Id, NegoBarangId = ResultNego.Id, TransactionLevelId = 1, CreatedBy = username, Created = DateTime.Now, RowStatus = true }; ResultNego.Modified = DateTime.Now; ResultNego.ModifiedBy = username; ResultNego.HasTransaction = true; long TransID = await dep.SaveTransaction(tran); if (TransID < 1) { response.Message = "Failed When Save Transaction"; response.IsSuccess = false; } else { TransactionJournal journal = new TransactionJournal() { TransactionId = tran.Id, BuyerId = tran.BuyerId, SellerId = tran.SellerId, NegoBarangId = tran.NegoBarangId, TransactionLevelId = tran.TransactionLevelId, Created = tran.Created, CreatedBy = tran.CreatedBy, RowStatus = tran.RowStatus, }; long JournalID = await IJournal.SaveTransactionJournal(journal); if (JournalID < 1) { log.Error("Failed when insert TransactionJournal, TransactionID = " + tran.Id); } response.Message = "Transaction Success."; response.IsSuccess = true; } INego.UpdatePost(ResultNego); return(response); }