public async Task <DataProviderModel <CreateDealModel> > CreateDeal(DealCreateModel createModel, DealType dealType) { var listQuery = new List <Query>(); var upsertDealIdentifier = Guid.NewGuid().ToString(); var upsertDealQuery = new Query(upsertDealIdentifier, "UpsertDeal"); upsertDealQuery.Parameters.Add(new QueryParameter("in", "Price", createModel.Price.ToString(), SqlDbType.Decimal)); upsertDealQuery.Parameters.Add(new QueryParameter("in", "Comment", createModel.Comment, SqlDbType.NVarChar)); if (dealType == DealType.Sell) { upsertDealQuery.Parameters.Add(new QueryParameter("in", "Account_Id", createModel.AccountId.ToString(), SqlDbType.Int)); } upsertDealQuery.Parameters.Add(new QueryParameter("in", "BuySell", dealType == DealType.Buy ? "B" : "S", SqlDbType.Int)); listQuery.Add(upsertDealQuery); foreach (var objectId in createModel.ObjectIdsToAdd) { var upsertDealObjectIdentifier = Guid.NewGuid().ToString(); var upsertDealObjectQuery = new Query(upsertDealObjectIdentifier, "UpsertDealObject"); upsertDealObjectQuery.ParentQueryGUID.Add(upsertDealIdentifier); upsertDealObjectQuery.Parameters.Add(new QueryParameter("in", "Object_Id", objectId.ToString(), SqlDbType.Int)); listQuery.Add(upsertDealObjectQuery); } var dealDeliveryIdentifier = Guid.NewGuid().ToString(); var dealDeliveryQuery = new Query(dealDeliveryIdentifier, "UpsertDealDelivery"); dealDeliveryQuery.ParentQueryGUID.Add(upsertDealIdentifier); dealDeliveryQuery.Parameters.Add(new QueryParameter("in", "DeliveryCptyService_Id", createModel.DeliveryTypeId.ToString(), SqlDbType.Int)); dealDeliveryQuery.Parameters.Add(new QueryParameter("in", "Weight_Decl", createModel.Weight.ToString(), SqlDbType.Int)); dealDeliveryQuery.Parameters.Add(new QueryParameter("in", "Length_Decl", createModel.Size.Length.ToString(), SqlDbType.Int)); dealDeliveryQuery.Parameters.Add(new QueryParameter("in", "Height_Decl", createModel.Size.Height.ToString(), SqlDbType.Int)); dealDeliveryQuery.Parameters.Add(new QueryParameter("in", "Width_Decl", createModel.Size.Width.ToString(), SqlDbType.Int)); var cityCode = createModel.DeleveryLocationType == DeleveryLocationType.City ? createModel.CityCode : createModel.LocalityCode; dealDeliveryQuery.Parameters.Add(new QueryParameter("in", "CityCode", cityCode, SqlDbType.NVarChar)); dealDeliveryQuery.Parameters.Add(new QueryParameter("in", "Address", createModel.Address, SqlDbType.NVarChar)); listQuery.Add(dealDeliveryQuery); var result = await _sessionQueryExecutor.Execute(listQuery).ConfigureAwait(false); var createDealModel = new CreateDealModel(); var createDealQuery = result.Queries.FirstOrDefault(q => q.Name == "UpsertDeal"); var dealIdParametr = createDealQuery?.Parameters.FirstOrDefault(p => p.Direction == "out" && p.Code == "Deal_Id"); if (dealIdParametr != null) { createDealModel.DealId = int.Parse(dealIdParametr.Value); } return(new DataProviderModel <CreateDealModel>(result.ResultMessage, createDealModel)); }
public async Task <IActionResult> CreateBuy(DealModifyModel model) { var objectIdsToAdd = model.SelectedDealObjects .Select(o => o.ObjectId) .ToList(); var createModel = new DealCreateModel(model.Price, model.Comment, null, model.DeleveryTypeId, model.Size, model.Weight, model.AddressModel.City.CityCode, model.AddressModel.Locality.LocalityCode, model.AddressModel.RegionCode, model.AddressModel.Address, (DeleveryLocationType)model.AddressModel.DeliveryLocationType, objectIdsToAdd); await _dealProvider.CreateDeal(createModel, DealType.Buy); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> CreateSell(SellDealModifyViewModel model) { var createUserAccountTask = Task.FromResult(new DataProviderModel <CreateUserAccountModel>(new ResultMessage(0, MessageType.Information, ""))); if (model.AccountAction == AccountAction.New) { createUserAccountTask = _userProvider.CreateUserAccount(model.PaymentNumber.Value, model.PaymentType); } var createUserAccount = (await createUserAccountTask).Model; var accountId = model.AccountAction == AccountAction.Existed ? model.UserAccountId.Value : createUserAccount.AccountId; var objectIdsToAdd = model.SelectedDealObjects .Select(o => o.ObjectId) .ToList(); var createModel = new DealCreateModel(model.Price, model.Comment, accountId, model.DeleveryTypeId, model.Size, model.Weight, model.AddressModel.City.CityCode, model.AddressModel.Locality.LocalityCode, model.AddressModel.RegionCode, model.AddressModel.Address, (DeleveryLocationType)model.AddressModel.DeliveryLocationType, objectIdsToAdd); await _dealProvider.CreateDeal(createModel, DealType.Sell); return(RedirectToAction(nameof(Index))); }
public ActionResult Create(DealCreateModel model) { try { if (!ModelState.IsValid) { var returnModel = CreateDealViewModel <DealCreateModel>(); returnModel.DealModel = model.DealModel; returnModel.Image = model.Image; returnModel.TagString = model.TagString; returnModel.AgesAvailable = DataContext.Ages.Select(x => new AgeModel { Id = x.Id, Name = x.Name }).ToList(); return(View(returnModel)); } var deal = new Deal { Title = model.DealModel.Title, Phone = model.DealModel.Phone, Description = model.DealModel.Description, IntroDescription = model.DealModel.IntroDescription, Url = model.DealModel.Url, AlwaysAvailable = model.DealModel.AlwaysAvailable, ExpiryDate = model.DealModel.AlwaysAvailable == true ? DateTime.Now : DateTime.Parse(model.DealModel.ExpiryDate), Likes = model.DealModel.Likes, Archived = model.DealModel.Archived, Expired = model.DealModel.Expired, Location = new Location { Name = model.DealModel.Location.Name, Geography = GeographyHelper.ConvertLatLonToDbGeography(model.DealModel.Location.Longitude.Value, model.DealModel.Location.Latitude.Value) }, Priority = model.DealModel.Priority, CityId = model.DealModel.City.Id, Address = new Address { AddressLine1 = model.DealModel.Address.AddressLine1, AddressLine2 = model.DealModel.Address.AddressLine2, PostCode = model.DealModel.Location.Name }, Season_Id = model.DealModel.Season.Id, Gender_Id = model.DealModel.Gender.Id }; //var deal = Mapper.Map<Deal>(model.DealModel); //deal.Address.PostCode = model.DealModel.Location.Name; //if (model.DealModel.AlwaysAvailable) deal.ExpiryDate = DateTime.Now; var tagList = model.TagString.Split(',').ToList(); foreach (var tag in tagList) { int tagId; deal.Tags.Add(int.TryParse(tag, out tagId) ? DataContext.Tags.Find(tagId) : new Tag { Name = tag }); } deal.Ages.Clear(); foreach (var age in model.AgeString) { int ageId; deal.Ages.Add(int.TryParse(age, out ageId) ? DataContext.Ages.First(t => t.Id == ageId) : new Age { Name = age }); } deal.Category = DataContext.Categories.Find(model.DealModel.Category.Id); deal.Company = DataContext.Companies.Find(model.DealModel.Company.Id); deal.Cost = DataContext.Costs.Find(model.DealModel.Cost.Id); var image = CreateImage(model.Image); deal.Images.Add(image); deal.Creator_User_Id = User.Identity.GetUserId();; DataContext.Deals.Add(deal); DataContext.Commit(); return(RedirectToAction("Index")); //return RedirectToAction("Edit/", new { id = deal.Id, edit = "true" }); } catch (Exception e) { Debug.Print(e.Message); return(View(model)); } }