public ActionResult DeleteOffer(int id) { User currentUser = UserService.GetUserByEmail(User.Identity.Name); string result = "error#" + Resource.NotFound; try { AutoExchange exchange = AutoExchangeService.GetByID(id); if (exchange == null) { throw new Exception(Resource.NotFound); } if (exchange.AutoOffered.UserID == currentUser.ID || exchange.AutoTarget.UserID == currentUser.ID) { AutoExchangeService.Delete(exchange); result = "success#1"; } else { throw new Exception(Resource.ThisOfferIsNotYours); } } catch (Exception ex) { result = "error#" + ex.Message; } return(Json(result)); }
public ActionResult AddExchangeOffer(AddExchangeOfferVM model) { Auto targetAuto = AutoService.GetPublishedByID(model.TargetAutoID); if (targetAuto == null) { return(HttpNotFound()); } User currentUser = UserService.GetUserByEmail(User.Identity.Name); AutoExchangeDetailsVM exchangeDetailsVM = null; try { AutoExchange newExchange = new AutoExchange() { OfferedAutoID = model.OfferedAutoID, TargetAutoID = model.TargetAutoID, DateCreated = DateTime.Now, CurrencyID = model.CurrencyID, DiffPrice = model.DiffPrice, DiffPriceDirection = model.DiffPriceDirection }; AutoExchangeService.Create(newExchange); Currency currency = CurrencyService.GetByID(newExchange.CurrencyID); Auto offeredAuto = AutoService.GetByID(model.OfferedAutoID); exchangeDetailsVM = targetAuto.AutoExchangesIncome.FirstOrDefault(ex => ex.ID == newExchange.ID); if (exchangeDetailsVM != null) { exchangeDetailsVM.Currency = currency.Symbol; exchangeDetailsVM.DeleteButtonIsAvailable = (currentUser != null && (currentUser.ID == offeredAuto.UserID || currentUser.ID == offeredAuto.UserID)); } } catch (Exception ex) { ViewBag.errorMsg = "Error: " + ex.Message; } return(PartialView("_ExchangeOffer", exchangeDetailsVM)); }