Beispiel #1
0
        public List <RequestBidsModel> GetBidsByMe(UsersModel user)
        {
            UsersModel userRepo = new UsersModel();
            List <RequestBidsModel> notifications = new List <RequestBidsModel>();

            using (var db = new angelhackEntities())
            {
                userRepo.CheckUserIfExist(db, user);
                userRepo.IsUserServiceProvider(db, user);


                var result = db.requestbids.Where(x => x.IsAwarded == false &&
                                                  x.UserID == user.ID
                                                  &&
                                                  (
                                                      x.request.StatusID != (int)RequestStatus.CANCELLED &&
                                                      x.request.StatusID != (int)RequestStatus.SERVED &&
                                                      x.request.StatusID != (int)RequestStatus.CLOSED
                                                  )

                                                  ).ToList();

                notifications = mapper.Map <List <requestbid>, List <RequestBidsModel> >(result);
            }


            return(notifications);
        }
Beispiel #2
0
        public void SendToNotifications(RequestModel notification, UsersModel user)
        {
            var        db       = new angelhackEntities();
            UsersModel userRepo = new UsersModel();

            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    userRepo.CheckUserIfExist(db, user);
                    userRepo.IsUserServiceProvider(db, user);


                    var newNotification = new requestnotification();
                    newNotification.DateLastUpdated = DateTime.Now;
                    newNotification.DateReceived    = DateTime.Now;
                    newNotification.IsAccepted      = false;
                    newNotification.RequestID       = notification.ID;
                    newNotification.RequestorID     = notification.UserID;
                    newNotification.UserID          = user.ID;
                    newNotification.IsAccepted      = false;
                    newNotification.IsDeclined      = false;

                    db.requestnotifications.Add(newNotification);


                    db.SaveChanges();
                    transaction.Commit();
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException dbU)
                {
                    transaction.Rollback();
                    Exception ex = dbU.GetBaseException();
                    throw new Exception(ex.Message);
                }
                catch (DbEntityValidationException dbEx)
                {
                    transaction.Rollback();
                    string errorMessages = null;

                    foreach (DbEntityValidationResult validationResult in dbEx.EntityValidationErrors)
                    {
                        string entityName = validationResult.Entry.Entity.GetType().Name;
                        foreach (DbValidationError error in validationResult.ValidationErrors)
                        {
                            errorMessages += (entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                        }
                    }

                    throw new Exception(errorMessages);
                }

                finally
                {
                    db.Database.Connection.Close();
                }
            }
        }
Beispiel #3
0
        public RequestBidsModel PlaceBid(RequestBidsModel bid, UsersModel user)
        {
            var        db       = new angelhackEntities();
            UsersModel userRepo = new UsersModel();

            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    userRepo.CheckUserIfExist(db, user);
                    userRepo.IsUserServiceProvider(db, user);

                    var newBid = new requestbid();
                    newBid.IsAwarded   = false;
                    newBid.Price       = bid.Price;
                    newBid.RequestID   = bid.RequestID;
                    newBid.ShopAddress = bid.ShopAddress;
                    newBid.ShopName    = bid.ShopName;
                    newBid.UserID      = user.ID;
                    newBid.BidDate     = DateTime.Now;
                    db.requestbids.Add(newBid);

                    db.SaveChanges();
                    transaction.Commit();


                    var getBid = db.requestbids.Where(x => x.ID == newBid.ID).FirstOrDefault();

                    return(mapper.Map <requestbid, RequestBidsModel>(getBid));
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException dbU)
                {
                    transaction.Rollback();
                    Exception ex = dbU.GetBaseException();
                    throw new Exception(ex.Message);
                }
                catch (DbEntityValidationException dbEx)
                {
                    transaction.Rollback();
                    string errorMessages = null;
                    foreach (DbEntityValidationResult validationResult in dbEx.EntityValidationErrors)
                    {
                        string entityName = validationResult.Entry.Entity.GetType().Name;
                        foreach (DbValidationError error in validationResult.ValidationErrors)
                        {
                            errorMessages += (entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                        }
                    }
                    throw new Exception(errorMessages);
                }
                finally
                {
                    db.Database.Connection.Close();
                }
            }
        }
Beispiel #4
0
        public List <RequestModel> PendingForMyBid(UsersModel user)
        {
            UsersModel          userRepo   = new UsersModel();
            List <RequestModel> myRequests = new List <RequestModel>();

            using (var db = new angelhackEntities())
            {
                userRepo.CheckUserIfExist(db, user);
                userRepo.IsUserServiceProvider(db, user);
                //var result = db.requestnotifications.Where(x=>x.IsAccepted == true &&
                //(
                // x.request.StatusID != (int)RequestStatus.CANCELLED &&
                //      x.request.StatusID != (int)RequestStatus.SERVED &&
                //        x.request.StatusID != (int)RequestStatus.CLOSED
                //    )

                //).Select(x=>x.request).ToList();

                var result = (from x in db.requestnotifications
                              join a in db.requestbids on new { RequestID = x.RequestID, UserID = x.UserID } equals new { RequestID = a.RequestID, UserID = a.UserID } into aa
                              from aax in aa.DefaultIfEmpty()
                              where aax == null &&
                              x.IsAccepted == true &&
                              (
                                  x.request.StatusID != (int)RequestStatus.CANCELLED &&
                                  x.request.StatusID != (int)RequestStatus.SERVED &&
                                  x.request.StatusID != (int)RequestStatus.CLOSED
                              )
                              select x.request).ToList();


                myRequests = mapper.Map <List <request>, List <RequestModel> >(result);
            }

            return(myRequests);
        }
Beispiel #5
0
        public void DeclineRequest(RequestModel notification, UsersModel user)
        {
            var        db       = new angelhackEntities();
            UsersModel userRepo = new UsersModel();

            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    userRepo.CheckUserIfExist(db, user);
                    userRepo.IsUserServiceProvider(db, user);


                    var newNotification = db.requestnotifications.Where(x => x.UserID == user.ID

                                                                        && x.IsDeclined == false
                                                                        &&
                                                                        (
                                                                            x.request.StatusID != (int)RequestStatus.CANCELLED &&
                                                                            x.request.StatusID != (int)RequestStatus.SERVED &&
                                                                            x.request.StatusID != (int)RequestStatus.CLOSED
                                                                        )
                                                                        &&
                                                                        x.RequestID == notification.ID).FirstOrDefault();

                    if (newNotification == null)
                    {
                        throw new Exception("Request no longer exist!");
                    }

                    newNotification.DateLastUpdated = DateTime.Now;
                    newNotification.IsDeclined      = true;
                    db.SaveChanges();
                    transaction.Commit();
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException dbU)
                {
                    transaction.Rollback();
                    Exception ex = dbU.GetBaseException();
                    throw new Exception(ex.Message);
                }
                catch (DbEntityValidationException dbEx)
                {
                    transaction.Rollback();
                    string errorMessages = null;

                    foreach (DbEntityValidationResult validationResult in dbEx.EntityValidationErrors)
                    {
                        string entityName = validationResult.Entry.Entity.GetType().Name;
                        foreach (DbValidationError error in validationResult.ValidationErrors)
                        {
                            errorMessages += (entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                        }
                    }

                    throw new Exception(errorMessages);
                }

                finally
                {
                    db.Database.Connection.Close();
                }
            }
        }