Ejemplo n.º 1
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");
            }
        }