public void Dispose()
 {
     using (MPContext context = new MPContext())
     {
         context.Dispose();
     }
 }
Example #2
0
        public ActionResult SubmitOrder(OrderModel order)
        {
            if (ModelState.IsValid)
            {
                using (MPContext dbContext = new MPContext())
                {
                    var currentUserId = User.Identity.GetUserId();

                    var currentCustomer = dbContext.Customer.Include("OrderList").FirstOrDefault(cust => cust.UserId == currentUserId);

                    var newOrder = order.GetOrderInfo(dbContext);
                    dbContext.Order.Add(newOrder);

                    if (currentCustomer == null)
                    {
                        Customer newCustomer = new Customer();
                        newCustomer.UserId = currentUserId;
                        newCustomer.Title  = User.Identity.Name;
                        newCustomer.OrderList.Add(newOrder);
                        dbContext.Customer.Add(newCustomer);
                    }
                    else
                    {
                        currentCustomer.OrderList.Add(newOrder);
                    }

                    dbContext.SaveChanges();
                }

                return(RedirectToAction("Index", "Orders"));
            }

            return(View("GoOrder", order));
        }
Example #3
0
        public JsonResult AddMessage(Message message, int offerId, int?threadId)
        {
            var result = new { message = string.Empty };

            using (var ctx = new MPContext())
            {
                if (threadId == null)
                {
                    var curOffer = ctx.Offer.First(offer => offer.Id == offerId);

                    Thread newThread = new Thread();
                    newThread.CreatedDateTime = DateTime.Now;
                    newThread.AuthorId        = message.AuthorId;
                    newThread.RecepientId     = message.RecepientId;
                    newThread.Offer           = curOffer;

                    ctx.Thread.Add(newThread);
                    ctx.SaveChanges();

                    message.Thread = newThread;
                }

                message.CreatedDateTime = DateTime.Now;
                ctx.Message.Add(message);
                ctx.SaveChanges();
                result = new { message = "Success" };
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #4
0
        public ActionResult ShowMyOrders()
        {
            var myOrdersModel = new OrderWithOffersListModel();
            var orderToPush   = new OrderWithOffers();

            using (MPContext dbContext = new MPContext())
            {
                var currentUserId = User.Identity.GetUserId();

                var currentCustomer = dbContext.Customer.Include("OrderList").FirstOrDefault(cust => cust.UserId == currentUserId);

                if (currentCustomer != null)
                {
                    foreach (var order in currentCustomer.OrderList)
                    {
                        var offers = dbContext.Offer.Include("Order").Where(offer => offer.Order.Id == order.Id);

                        orderToPush.Id                 = order.Id;
                        orderToPush.ServiceType        = order.ServiceType;
                        orderToPush.Title              = order.Title;
                        orderToPush.SourceAddress      = order.SourceAddress;
                        orderToPush.DestinationAddress = order.DestinationAddress;
                        orderToPush.OrderDueDateTime   = order.OrderDueDateTime;
                        orderToPush.OrderCost          = order.OrderCost;
                        orderToPush.OrderCurrency      = order.OrderCurrency;
                        orderToPush.Offers             = offers.ToList();

                        myOrdersModel.Orders.Add(orderToPush);
                    }
                }


                return(View("MyOrders", myOrdersModel));
            }
        }
Example #5
0
        public Order GetOrderInfo(MPContext mpContext)
        {
            Order newOrder = new Order();

            newOrder.Title            = orderTitle;
            newOrder.Description      = orderDescription;
            newOrder.OrderDateTime    = orderDateTime;
            newOrder.OrderDueDateTime = orderDueDateTime;

            //ServiceCathegory selectedCathegory = mpContext.ServiceCathegory.Single(c => c.Id == cathegoryId);
            ServiceType selectedType = mpContext.ServiceType.First(c => c.Id == typeId);

            //mpContext.ServiceType.Attach(selectedType);
            newOrder.ServiceType = selectedType;

            newOrder.SourceAddress      = sourceAddress;
            newOrder.DestinationAddress = destinationAddress;
            newOrder.ContactTitle       = contactTitle;
            newOrder.ContactEmail       = contactEmail;
            newOrder.ContactPhoneNumber = contactPhoneNumber;
            newOrder.OrderCost          = orderCost;

            Currency selectedCurrency = mpContext.Currency.Single(c => c.Id == currencyId);

            //mpContext.Currency.Attach(selectedCurrency);
            newOrder.OrderCurrency = selectedCurrency;

            return(newOrder);
        }
Example #6
0
        // GET: Orders
        public ActionResult Index()
        {
            var orderList = new OrderListModel();

            using (MPContext dbContext = new MPContext())
            {
                //IQueryable<Order> query = dbContext.Order.Include("ServiceType");
                foreach (var order in dbContext.Order.Include("ServiceType").Include("OrderCurrency"))
                {
                    orderList.Orders.Add(order);
                }
            }
            return(View(orderList));
        }
Example #7
0
        public ActionResult OfferAcceptanceForm(int offerId)
        {
            ViewBag.ordersDone = 0;

            var curOfferModel = new OfferModel();

            using (MPContext dbContext = new MPContext())
            {
                var curOffer = dbContext.Offer.Include("Executor").First(offer => offer.Id == offerId);
                curOfferModel.executor.Title  = curOffer.Executor.Title;
                curOfferModel.description     = curOffer.Description;
                curOfferModel.executor.Rating = curOffer.Executor.Rating;
            }

            return(View("OfferAcceptanceForm", curOfferModel));
        }
Example #8
0
        public ActionResult GoOrder(FormCollection form)
        {
            var orderTitle = form["orderTitle"].ToString();

            OrderModel newOrder = new OrderModel();

            newOrder.orderTitle = orderTitle;

            using (var ctx = new MPContext())
            {
                var query = from cathegory in ctx.ServiceCathegory
                            orderby cathegory.Id
                            select cathegory;


                foreach (var item in query)
                {
                    var cathegoryId    = item.Id;
                    var cathegoryTitle = item.Title;

                    ServiceCathegory newCat = new ServiceCathegory(cathegoryId, cathegoryTitle);
                    newOrder.orderCathegoryList.Add(newCat);
                }

                var typeQuery = from type in ctx.ServiceType
                                orderby type.Title
                                select type;

                foreach (var typeItem in typeQuery)
                {
                    ServiceType newType = new ServiceType(typeItem.Id, typeItem.Title, typeItem.ServiceCathegory);
                    newOrder.orderTypeList.Add(newType);
                }

                var currencyQuery = from currency in ctx.Currency
                                    orderby currency.Title
                                    select currency;

                foreach (var currencyItem in currencyQuery)
                {
                    Currency newCurrency = new Currency(currencyItem.Id, currencyItem.Title);
                    newOrder.currencyList.Add(newCurrency);
                }
            }

            return(View(newOrder));
        }
Example #9
0
        public ActionResult AcceptOffer(int offerId)
        {
            using (MPContext dbContext = new MPContext())
            {
                var curOffer = dbContext.Offer.Include("Executor").First(offer => offer.Id == offerId);

                OfferTracking newOfferTracking = new OfferTracking();
                newOfferTracking.Offer   = curOffer;
                newOfferTracking.Created = DateTime.Now;
                newOfferTracking.Status  = new OfferStatus("Accepted");
                dbContext.OfferTracking.Add(newOfferTracking);

                dbContext.SaveChanges();
            }

            return(RedirectToAction("ShowMyOrders", "Orders"));
        }
Example #10
0
        // GET: Messages
        public ActionResult Index()
        {
            ThreadModel myThreads = new ThreadModel();

            using (var ctx = new MPContext())
            {
                var currentUserId = User.Identity.GetUserId();
                var threadList    = from th in ctx.Thread
                                    orderby th.CreatedDateTime descending
                                    where th.AuthorId == currentUserId || th.RecepientId == currentUserId
                                    select th;

                foreach (Thread thread in threadList)
                {
                    ThreadEntity newThread = new ThreadEntity();

                    var executorVal = (from executor in ctx.Executor
                                       where executor.UserId == currentUserId
                                       select executor).FirstOrDefault();

                    var customerVal = (from customer in ctx.Customer
                                       where customer.UserId == currentUserId
                                       select customer).FirstOrDefault();

                    var userTitle = executorVal != null ? executorVal.Title : customerVal.Title;

                    var lastMessage = (from message in ctx.Message
                                       orderby message.CreatedDateTime descending
                                       where message.Thread.Id == thread.Id
                                       select message).FirstOrDefault();

                    newThread.AuthorTitle         = userTitle;
                    newThread.LastMessageDateTime = lastMessage.CreatedDateTime;
                    newThread.LastMessageText     = lastMessage.MessageText;

                    myThreads.ThreadList.Add(newThread);
                }
            }

            return(View("ThreadList", myThreads));
        }
Example #11
0
        public ActionResult TakeOrder(int Id, FormCollection form)
        {
            var curOrderModel = new OrderModel();

            using (MPContext dbContext = new MPContext())
            {
                var currentUserId = User.Identity.GetUserId();

                var curOrder = dbContext.Order.Include("ServiceType").Include("ServiceType.ServiceCathegory").Include("OrderCurrency").First(order => order.Id == Id);

                var curExecutor = dbContext.Executor.FirstOrDefault(ex => ex.UserId == currentUserId);

                var newCreatedStatus = dbContext.OfferStatus.FirstOrDefault(s => s.Title == "Created");

                string descriptionText = form["description"];

                Offer newOffer = new Offer();
                newOffer.Order       = curOrder;
                newOffer.Description = descriptionText;
                newOffer.Executor    = curExecutor;
                dbContext.Offer.Add(newOffer);
                dbContext.SaveChanges();

                OfferTracking newCreatedTracking = new OfferTracking();
                newCreatedTracking.Status  = newCreatedStatus;
                newCreatedTracking.Created = DateTime.Now;
                newCreatedTracking.Offer   = newOffer;
                dbContext.OfferTracking.Add(newCreatedTracking);
                dbContext.SaveChanges();

                //curOrderModel.cathegoryId = curOrder.ServiceType.ServiceCathegory.Id;
                //curOrderModel.cathegoryTitle = curOrder.ServiceType.ServiceCathegory.Title;
                //curOrderModel.orderTitle = curOrder.Title;//curOrderModel.sourceAddress = curOrder.SourceAddress;
                //curOrderModel.destinationAddress = curOrder.DestinationAddress;
                //curOrderModel.orderDueDateTime = curOrder.OrderDueDateTime;
                //curOrderModel.orderCost = curOrder.OrderCost;
                //curOrderModel.orderCurrency = curOrder.OrderCurrency;
            }

            return(View("Order", curOrderModel));
        }
Example #12
0
        public ActionResult ShowOrder(int Id)
        {
            var curOrderModel = new OrderModel();

            using (MPContext dbContext = new MPContext())
            {
                var curOrder = dbContext.Order.Include("ServiceType").Include("ServiceType.ServiceCathegory").Include("OrderCurrency").First(order => order.Id == Id);

                curOrderModel.orderId            = curOrder.Id;
                curOrderModel.cathegoryId        = curOrder.ServiceType.ServiceCathegory.Id;
                curOrderModel.cathegoryTitle     = curOrder.ServiceType.ServiceCathegory.Title;
                curOrderModel.orderTitle         = curOrder.Title;
                curOrderModel.sourceAddress      = curOrder.SourceAddress;
                curOrderModel.destinationAddress = curOrder.DestinationAddress;
                curOrderModel.orderDueDateTime   = curOrder.OrderDueDateTime;
                curOrderModel.orderCost          = curOrder.OrderCost;
                curOrderModel.orderCurrency      = curOrder.OrderCurrency;
            }

            return(View("Order", curOrderModel));
        }
Example #13
0
        public JsonResult GetMessages(int threadId)
        {
            var result = new LinkedList <object>();

            using (var ctx = new MPContext())
            {
                List <Message> messages = ctx.Message.Where(m => m.Thread.Id == threadId).OrderBy(m => m.CreatedDateTime).ToList();

                foreach (var message in messages)
                {
                    result.AddLast(new
                    {
                        Username     = message.AuthorId,
                        PostDateTime = message.CreatedDateTime.ToString("dd MMMM yyyy hh:mm"),
                        MessageBody  = message.MessageText,
                        ThreadId     = message.Thread.Id
                    });
                }
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Example #14
0
        public ActionResult Conversation(string executorId, int offerId)
        {
            ThreadEntity currentThread;

            using (var ctx = new MPContext())
            {
                var currentUserId   = User.Identity.GetUserId();
                var currentUserName = User.Identity.Name;

                var executorVal = (from executor in ctx.Executor
                                   where executor.UserId == currentUserId
                                   select executor).FirstOrDefault();

                var customerVal = (from customer in ctx.Customer
                                   where customer.UserId == currentUserId
                                   select customer).FirstOrDefault();

                var userId = executorVal != null ? executorVal.Id : customerVal.Id;

                currentThread = new ThreadEntity(ctx, executorId, offerId, userId, currentUserName);
            }

            return(View("Conversation", currentThread));
        }
Example #15
0
        public ActionResult Index()
        {
            using (var ctx = new MPContext())
            {
                var cust = new Customer();
                cust.Title = "New customer";

                //ctx.Customer.Add(cust);
                //ctx.SaveChanges();

                //// Display all Blogs from the database
                //var query = from b in ctx.Customer
                //            orderby b.Title
                //            select b;

                //Console.WriteLine("All blogs in the database:");
                //foreach (var item in query)
                //{
                //    var test = item.Title;
                //}
            }

            return(View());
        }
Example #16
0
        public ActionResult OffersByOrder(int orderId)
        {
            var curOfferListModel = new OfferListModel();

            using (MPContext dbContext = new MPContext())
            {
                var curOrder = dbContext.Order.Include("ServiceType")
                               .Include("ServiceType.ServiceCathegory")
                               .Include("OrderCurrency")
                               .First(order => order.Id == orderId);

                curOfferListModel.order = curOrder;

                var offerList = dbContext.Offer.Include("Executor").Where(offer => offer.Order.Id == orderId);

                foreach (var offer in offerList)
                {
                    OfferModel mOffer = new OfferModel();
                    mOffer.Id          = offer.Id;
                    mOffer.executor    = offer.Executor;
                    mOffer.description = offer.Description;

                    var tracking = dbContext.OfferTracking.Include("Status").Where(o => o.Offer.Id == offer.Id).OrderByDescending(o => o.Id);

                    var offerStatus = tracking.FirstOrDefault();

                    if (offerStatus != null)
                    {
                        mOffer.offerStatus = offerStatus.Status.Title;
                        curOfferListModel.offers.Add(mOffer);
                    }
                }
            }

            return(View("OffersByOrder", curOfferListModel));
        }
Example #17
0
 public Cleanup(MPContext ctx)
 {
     context = ctx;
 }
Example #18
0
 public MainRepository(MPContext _context)
 {
     context = _context;
 }
Example #19
0
 public Converter(MPContext ctx, IConfiguration cfg)
 {
     context  = ctx;
     config   = cfg;
     analyzer = new MP.Core.Analysis(context, config);
 }
Example #20
0
 public Analysis(MPContext ctx, IConfiguration cfg)
 {
     context = ctx;
     config  = cfg;
 }
Example #21
0
File: App.cs Project: vongrippen/mp
 public App(IConfiguration config, MPContext ctx)
 {
     _config  = config;
     _context = ctx;
 }
Example #22
0
 public Product_Repository(MPContext _context)
 {
     context = _context;
 }
Example #23
0
 public UnitOfWork(MPContext _db)
 {
     db = _db;
 }