Ejemplo n.º 1
0
        public void removeRentalEquipment(int rentalId, int equitmentid)
        {
            using (var context = new eToolsContext())
            {
                //Return equipment
                RentalEquipment checkoutEquipment = context.RentalEquipments
                                                    .Where(x => (x.RentalEquipmentID == equitmentid)).FirstOrDefault();
                //Update availability
                checkoutEquipment.Available = true;

                //COMMIT UPDATE***
                context.Entry(checkoutEquipment).State = EntityState.Modified;
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////



                //retrive rentaldetails table that will destoryed
                RentalDetail existingRentalEquipment = context.RentalDetails
                                                       .Where(x => ((x.RentalID == rentalId) &&
                                                                    (x.RentalEquipmentID == equitmentid))).FirstOrDefault();

                //COMMIT DELETE***
                context.Entry(existingRentalEquipment).State = EntityState.Deleted;

                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////



                //Finalize Transaction!
                context.SaveChanges();
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
        }
Ejemplo n.º 2
0
        public void Create_RentalDetails(int rentalID, int equipmentID)
        {
            using (var context = new eToolsContext())
            {
                RentalEquipment equipment = context.RentalEquipments.Where(x => x.RentalEquipmentID.Equals(equipmentID)).Select(x => x).FirstOrDefault();

                RentalDetail exists = context.RentalDetails.Where(x => x.RentalEquipmentID.Equals(equipmentID) && x.RentalID.Equals(rentalID)).Select(x => x).FirstOrDefault();

                if (exists != null)//equipmnet already in there
                {
                    throw new BusinessRuleException("Already Renting This Equipment", "This piece of equipment is already on this rental");
                }
                else
                {
                    RentalDetail detail = new RentalDetail();

                    detail.RentalID        = rentalID;
                    detail.RentalEquipment = equipment;
                    detail.ConditionOut    = equipment.Condition;
                    detail.ConditionIn     = equipment.Condition;

                    context.RentalDetails.Add(detail);

                    context.SaveChanges();
                }
            }
        }
 public int newReturn_Update(RentalEquipment item)
 {
     using (var context = new eToolsContext())
     {
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         return(context.SaveChanges());
     }
 }
        public void deleteRental(int rentalid)
        {
            using (var context = new eToolsContext())
            {
                //.FirstOrDefault() is added in Visual Studio not in LINQ, as it does NOT AUTO. CONVERT!!
                Rental rental = context.Rentals.Where(x => (x.RentalID == rentalid)).FirstOrDefault();

                //A return of 1 means an EXACT MATCH
                //either there is a value or not; 1 or 0
                if (rental == null)
                {
                    throw new BusinessRuleException("No such rental exists!", logger);
                }
                else
                {
                    //Heavy Query!
                    DELETE_RentalDetailsTable_UPDATE_RentalEquipmentTable removeList = context.Rentals.Where(x => (x.RentalID == rentalid))
                                                                                       .Select(x =>
                                                                                               new DELETE_RentalDetailsTable_UPDATE_RentalEquipmentTable()
                    {
                        deleteSet = x.RentalDetails.Select(y =>
                                                           new SingleEquipmentPairWithRentalDetailDelete()
                        {
                            _RentalDetailTable    = y,
                            _RentalEquipmentTable = y.RentalEquipment
                        })
                    }).FirstOrDefault();


                    //The.find(...) returns an entity based on...ID

                    //DTO
                    foreach (var remove in removeList.deleteSet)
                    {
                        //I not sure if this returns or mods anything
                        //ii._RentalEquipmentTable.Available = true;

                        //better way... not this, but use above query
                        // ...== ii._RentalEquipmentTable.RentalEquipmentID)... id the equipment
                        //RentalEquipment updatedEquipment = context.RentalEquipments
                        //                                            .Where(x => (x.RentalEquipmentID == ii._RentalEquipmentTable.RentalEquipmentID)).FirstOrDefault();

                        RentalEquipment updatedEquipment = remove._RentalEquipmentTable;
                        updatedEquipment.Available            = true;
                        context.Entry(updatedEquipment).State = EntityState.Modified;     //Update Equipment ....Available = true; aka returned


                        RentalDetail deletedRentalDetail = remove._RentalDetailTable;
                        context.Entry(deletedRentalDetail).State = EntityState.Deleted;  //Delete RentalDetails
                    }

                    //Delete Rental
                    context.Entry(rental).State = EntityState.Deleted;
                }
                //Commit Transaction
                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        public void addRentalEquipment(int rentalId, int equitmentid)
        {
            using (var context = new eToolsContext())
            {
                //Checkout equipment
                RentalEquipment checkoutEquipment = context.RentalEquipments
                                                    .Where(x => (x.RentalEquipmentID == equitmentid)).FirstOrDefault();
                //Update
                checkoutEquipment.Available = false;

                //COMMIT UPDATE***
                context.Entry(checkoutEquipment).State = EntityState.Modified;
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////


                //create Rental Details
                RentalDetail newRentalEquipment = new RentalDetail();
                //Recived values
                newRentalEquipment.RentalID          = rentalId;
                newRentalEquipment.RentalEquipmentID = equitmentid;


                //unmutatble Values
                newRentalEquipment.DailyRate = context.RentalEquipments
                                               .Where(x => (x.RentalEquipmentID == equitmentid))
                                               .Select(x => x.DailyRate).FirstOrDefault();

                newRentalEquipment.ConditionOut = context.RentalEquipments
                                                  .Where(x => (x.RentalEquipmentID == equitmentid))
                                                  .Select(x => x.Condition).FirstOrDefault();


                //Pending return
                //Set to default values
                newRentalEquipment.Days             = 1; //bussiness rule!
                newRentalEquipment.ConditionIn      = "Has not been returned";
                newRentalEquipment.DamageRepairCost = 0.0m;
                newRentalEquipment.Comments         = "";

                //COMMIT ADD***
                context.Entry(newRentalEquipment).State = EntityState.Added;
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////


                //Finalize Transaction!
                context.SaveChanges();
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
        }
Ejemplo n.º 6
0
        protected void EquipmentAdd(object sender, CommandEventArgs e)
        {
            string username = User.Identity.Name;
            int    employeeid;
            int    equipmentid = int.Parse(e.CommandArgument.ToString());
            int    customerid  = int.Parse(CurrentCustomerID.Text);

            //ApplicationUserManager secmgr = new ApplicationUserManager(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            //EmployeeInfo info = secmgr.User_GetEmployee(username);
            employeeid = 1;//info.EmployeeID;
            List <RentalDetailRecord> details   = new List <RentalDetailRecord>();
            List <RentalEquipment>    einfoList = new List <RentalEquipment>();

            ShowCouponForm();

            if (employeeid == 0)
            {
                MessageUserControl.ShowInfo("Warning", "Please login as an Employee!");
            }
            else
            {
                MessageUserControl.TryRun(() =>
                {
                    RentalRecord Record       = null;
                    RentalDetailRecord Detail = null;


                    if (CurrentRentalDetailListView.Items.Count == 0)
                    {
                        Record = new RentalRecord();
                        Detail = new RentalDetailRecord();

                        Detail.RentalEquipmentID = equipmentid;

                        RentalEquipmentController resysmgr = new RentalEquipmentController();
                        RentalEquipment reinfo             = resysmgr.Equipment_Find_byID(equipmentid);

                        Detail.DailyRate    = reinfo.DailyRate;
                        Detail.Days         = 1;
                        Detail.ConditionOut = reinfo.Condition;
                        Detail.Paid         = false;


                        Record.RentalDate = DateTime.Now;
                        if (Detail == null)
                        {
                            MessageUserControl.ShowInfo("Warning", "Create new Rental failed!");
                        }
                        else
                        {
                            details.Add(Detail);
                        }

                        Record.Details           = details;
                        RentalController rsysmgr = new RentalController();
                        rsysmgr.Create_newRentalRecord(customerid, employeeid, Record);

                        einfoList.Add(reinfo);

                        CurrentRentalDetailListView.DataSource = einfoList;
                        CurrentRentalDetailListView.DataBind();
                    }
                    else
                    {
                        Detail = new RentalDetailRecord();
                        Detail.RentalEquipmentID = equipmentid;



                        RentalDetailController rdsysmgr = new RentalDetailController();
                        var dinfo = rdsysmgr.List_RentalDetail_forRental(customerid, employeeid, Record.RentalDate);

                        foreach (var item in dinfo)
                        {
                            RentalEquipmentController resysmgr = new RentalEquipmentController();
                            RentalEquipment reinfo             = resysmgr.Equipment_Find_byID(item.RentalEquipmentID);
                            Detail.DailyRate    = reinfo.DailyRate;
                            Detail.Days         = 1;
                            Detail.ConditionOut = reinfo.Condition;
                            Detail.Paid         = false;
                            einfoList.Add(reinfo);
                        }

                        CurrentRentalDetailListView.DataSource = einfoList;
                        CurrentRentalDetailListView.DataBind();
                    }
                }, "Found", "Customer(s) has been found");
            }
        }