Пример #1
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));
        }
Пример #2
0
 public void Save(TblProduct obj)
 {
     if (obj.Productid == 0)
     {
         context.TblProduct.Add(obj);
         context.SaveChanges();
     }
     else
     {
         context.Entry <TblProduct>(obj).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #3
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));
        }
Пример #4
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));
        }
Пример #5
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"));
        }
Пример #6
0
 public virtual void Save()
 {
     context.SaveChanges();
 }