public AddOrderResult AddOrder(AddOrderModel model) { var order = _mapper.Map <Order>(model); order.Date = DateTime.Now; order.UserId = _userManager.FindByEmailAsync(User.Identity.Name).Result.Id; order.OrderStatusId = -1; ctx.Orders.Add(order); ctx.SaveChanges(); return(new AddOrderResult() { Successful = true }); }
public async Task <Result> AddChat(AddChatModel model) { var user = await _userManager.FindByEmailAsync(User.Identity.Name); var chat = new Chat() { Name = user.GetCompany(ctx).Name + " - " + ctx.Services.Single(s => s.Id == model.ServiceId).Name, Description = "—", ServiceId = model.ServiceId, CompanyId = user.GetCompany(ctx).Id }; ctx.Chats.Add(chat); ctx.SaveChanges(); ctx.ChatUsers.Add( new ChatUser() { UserId = user.Id, ChatId = chat.Id } ); ctx.SaveChanges(); ctx.Messages.Add( new Message() { Date = DateTime.Now, ChatId = chat.Id, Text = "Conversation was started", } ); ctx.SaveChanges(); return(new Result() { Successful = true }); }