Ejemplo n.º 1
0
        public RequestBidsModel ViewBid(int requestID, UsersModel user)
        {
            UsersModel       userRepo = new UsersModel();
            RequestBidsModel bid      = new RequestBidsModel();

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

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

                                                  ).FirstOrDefault();

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


            return(bid);
        }
Ejemplo n.º 2
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();
                }
            }
        }
Ejemplo n.º 3
0
        public void AcceptBid(RequestBidsModel bid, UsersModel user)
        {
            var        db       = new angelhackEntities();
            UsersModel userRepo = new UsersModel();

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

                    var chkBid = db.requestbids.Where(x => x.ID == bid.ID && x.request.UserID == user.ID).FirstOrDefault();

                    if (chkBid == null)
                    {
                        throw new Exception("Bid does not exist!");
                    }

                    chkBid.request.StatusID = (int)RequestStatus.CONFIRMED;
                    chkBid.IsAwarded        = 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();
                }
            }
        }
Ejemplo n.º 4
0
        public void ConfirmPayment(RequestBidsModel bidRef, UsersModel auth)
        {
            using (var db = new angelhackEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var bid = db.requestbids.Where(x => x.ID == bidRef.ID).FirstOrDefault();

                        if (bid == null)
                        {
                            throw new Exception("Bid does not exist!");
                        }

                        if (bid.request.StatusID != (int)RequestStatus.SERVED && bid.request.StatusID != (int)RequestStatus.CONFIRMED)
                        {
                            throw new Exception("Bid does not exist!");
                        }

                        bid.request.StatusID = (int)RequestStatus.CLOSED;


                        db.SaveChanges();


                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                    }
                    finally
                    {
                        db.Database.Connection.Close();
                    }
                }
            }
        }