コード例 #1
0
        public ActionResult Edit(Models.VehicleBooking booking)
        {
            try
            {
                var db = new CodeFirst.CodeFirst();

                var adjBooking = db.Vehicle_Booking_Line.Where(v => v.VehicleBookingID == booking.VehicleBookingID).FirstOrDefault();
                adjBooking.EndTime   = booking.EndTime;
                adjBooking.Reason    = booking.Reason;
                adjBooking.UserID    = booking.UserID;
                adjBooking.ProjectID = booking.ProjectID;

                db.SaveChanges();

                return(Json(new
                {
                    ResultValue = "Success"
                }));
            }
            catch
            {
                return(Json(new
                {
                    ResultValue = "Error"
                }));
            }
        }
コード例 #2
0
        public ActionResult Create([Bind(Prefix = "")] Models.JobTitle model)
        {
            if (ModelState.IsValid)
            {
                var db = new CodeFirst.CodeFirst();
                if (db.Employee_Title.Count() > 0)
                {
                    var item = db.Employee_Title.OrderByDescending(a => a.JobTitleID).FirstOrDefault();

                    db.Employee_Title.Add(new CodeFirst.Employee_Title
                    {
                        JobTitleID = item.JobTitleID + 1,
                        TitleName  = model.TitleName
                    });
                }
                else
                {
                    db.Employee_Title.Add(new CodeFirst.Employee_Title
                    {
                        JobTitleID = 1,
                        TitleName  = model.TitleName
                    });
                }

                db.SaveChanges();
                model.JavaScriptToRun = "mySuccess()";
                TempData["model"]     = model;
                return(RedirectToAction("Index", "JobTitle"));
            }

            return(View("Index", model));
        }
コード例 #3
0
        public ActionResult Modify([Bind(Prefix = "")] Models.Vehicle model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var vehicle = db.Vehicles.Where(v => v.VehicleID == model.VehicleID).SingleOrDefault();

                if (vehicle != null)
                {
                    vehicle.Brand                   = model.Brand;
                    vehicle.Model                   = model.Model;
                    vehicle.NumberPlate             = model.NumberPlate;
                    vehicle.DateOfPurchase          = model.DateofPurchase;
                    vehicle.DateofLastRepair        = model.DateofLastRepair;
                    vehicle.DateofLicencePurchase   = model.DateofLicencePurchase;
                    vehicle.LicenseExpireDate       = model.LicenseExpireDate;
                    vehicle.ServiceIntervalInMonths = model.ServiceIntervalInMonths;
                    vehicle.ServiceIntervalInKMs    = model.ServiceIntervalInKMs;
                    vehicle.TypeID                  = model.TypeID;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "Vehicles"));
            }
            model.VehicleTypes = db.Vehicle_Type.ToList();
            return(View("Index", model));
        }
コード例 #4
0
        public ActionResult Modify([Bind(Prefix = "")] Models.EquipmentRepairRequest model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var request = db.Repair_Request.Where(v => v.RequestID == model.RequestID).SingleOrDefault();

                if (request != null)
                {
                    request.RequestID   = model.RequestID;
                    request.Approved    = model.Approved;
                    request.Repaired    = model.Repaired;
                    request.Reason      = model.Reason;
                    request.EquipmentID = model.EquipmentID;
                    request.RepPersonID = model.RepPersonID;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "EquipmentRepairRequests"));
            }
            model.repairPeople = db.RepairPersons.ToList();
            return(View("Index", model));
        }
コード例 #5
0
        public ActionResult RemoveReading(string bookingID)
        {
            try
            {
                var db = new CodeFirst.CodeFirst();

                var intBookingID = Int32.Parse(bookingID);
                var adjBooking   = db.Vehicle_Booking_Line.Where(v => v.VehicleBookingID == intBookingID).FirstOrDefault();
                adjBooking.OdoEnd = 0;

                db.SaveChanges();

                return(Json(new
                {
                    ResultValue = "Success"
                }));
            }
            catch
            {
                return(Json(new
                {
                    ResultValue = "Error"
                }));
            }
        }
コード例 #6
0
        public ActionResult Create([Bind(Prefix = "")]Models.VehicleType model)
        {
            if (ModelState.IsValid)
            {
                var db = new CodeFirst.CodeFirst();
                if (db.Vehicle_Type.Count() > 0)
                {
                    var item = db.Vehicle_Type.OrderByDescending(a => a.TypeID).FirstOrDefault();

                    db.Vehicle_Type.Add(new CodeFirst.Vehicle_Type
                    {
                        TypeID = item.TypeID + 1,
                        Name = model.Name,
                        Description = model.Description,
                    });
                }
                else
                {
                    db.Vehicle_Type.Add(new CodeFirst.Vehicle_Type
                    {
                        TypeID = 1,
                        Name = model.Name,
                        Description = model.Description,
                    });
                }
                
                db.SaveChanges();
                model.JavaScriptToRun = "mySuccess()";
                TempData["model"] = model;
                return RedirectToAction("Index", "VehicleTypes");
            }

            return View("Add", model);
        }
コード例 #7
0
        public ActionResult Delete(string donationID)
        {
            try
            {
                var db            = new CodeFirst.CodeFirst();
                var intDonationID = int.Parse(donationID);
                var Donation      = db.Donations.Where(v => v.DonationID == intDonationID).FirstOrDefault();

                foreach (var item in Donation.Donation_Line.ToList())
                {
                    var forTotal = db.Donation_Item.Where(d => d.DonationItemID == item.DonationItemID).FirstOrDefault();
                    forTotal.TotalAmount -= item.DonationAmount;
                }

                db.Donation_Line.RemoveRange(Donation.Donation_Line);
                db.Donations.Remove(Donation);
                db.SaveChanges();

                var redirectUrl = new UrlHelper(Request.RequestContext).Action("Index", "Donation");
                return(Json(new { Url = redirectUrl }));
            }
            catch (Exception error)
            {
                return(Json(new { Url = "Cascading error!" }));
            }
        }
コード例 #8
0
        public ActionResult Modify([Bind(Prefix = "")] Models.SoftwareLicensesLine model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var line = db.Software_Licenses_Line.Where(v => v.LineID == model.LineID).SingleOrDefault();

                if (line != null)
                {
                    line.EquipmentID       = model.EquipmentID;
                    line.LicenceID         = model.LicenceID;
                    line.LastActivatedDate = model.LastActivatedDate;
                    line.Activated         = model.Activated;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "EquipmentSoftwareLicenses"));
            }

            model.Softwares  = db.Software_Licenses.ToList();
            model.Equipments = db.Equipments.AsEnumerable().Select(e => new SelectListItem
            {
                Value = e.EquipmentID.ToString(),
                Text  = e.ManufacturerName + " " + e.ModelNumber
            }).ToList();
            return(View("Index", model));
        }
コード例 #9
0
        public ActionResult Remove(string bookingID)
        {
            try
            {
                var db           = new CodeFirst.CodeFirst();
                var intBookingID = int.Parse(bookingID);
                var theBookingID = db.Equipment_Booking.Where(t => t.EquipmentBookingID == intBookingID).FirstOrDefault();
                var booking      = db.Equipment_Booking_Line.Where(t => t.BookingID == intBookingID).FirstOrDefault();
                db.Equipment_Booking_Line.Remove(booking);
                db.Equipment_Booking.Remove(theBookingID);
                db.SaveChanges();

                return(Json(new
                {
                    ResultValue = "Success"
                }));
            }
            catch
            {
                return(Json(new
                {
                    ResultValue = "Fail"
                }));
            }
        }
コード例 #10
0
        public ActionResult Modify([Bind(Prefix = "")] Models.Donor_Person model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var DonorPerson = db.Donor_Person.Where(v => v.DonorPID == model.DonorPID).SingleOrDefault();

                if (DonorPerson != null)
                {
                    DonorPerson.DonorPID      = model.DonorPID;
                    DonorPerson.FirstName     = model.FirstName;
                    DonorPerson.MiddleName    = model.MiddleName;
                    DonorPerson.SecondName    = model.SecondName;
                    DonorPerson.Initials      = model.Initials;
                    DonorPerson.CellNum       = model.CellNum;
                    DonorPerson.PersonalEmail = model.PersonalEmail;
                    DonorPerson.Thanked       = model.Thanked;
                    DonorPerson.StreetAddress = model.StreetAddress;
                    DonorPerson.City          = model.City;
                    DonorPerson.AreaCode      = model.AreaCode;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "DonorPerson"));
            }

            return(View("Index", model));
        }
コード例 #11
0
        public ActionResult RemovePages(string bookingID)
        {
            try
            {
                var db = new CodeFirst.CodeFirst();

                var intBookingID = Int32.Parse(bookingID);
                var adjBooking   = db.Equipment_Booking_Line.Where(v => v.BookingID == intBookingID).FirstOrDefault();
                adjBooking.PagesPrinted = 0;

                db.SaveChanges();

                return(Json(new
                {
                    ResultValue = "Success"
                }));
            }
            catch
            {
                return(Json(new
                {
                    ResultValue = "Error"
                }));
            }
        }
コード例 #12
0
        public ActionResult Edit(Models.EquipmentBooking booking)
        {
            try
            {
                var db = new CodeFirst.CodeFirst();

                var adjBooking = db.Equipment_Booking_Line.Where(v => v.BookingID == booking.BookingID).FirstOrDefault();
                adjBooking.TimeOut   = booking.TimeOut;
                adjBooking.UserID    = booking.UserID;
                adjBooking.ProjectID = booking.ProjectID;

                db.SaveChanges();

                return(Json(new
                {
                    ResultValue = "Success"
                }));
            }
            catch
            {
                return(Json(new
                {
                    ResultValue = "Error"
                }));
            }
        }
コード例 #13
0
        public void Capture(string userID)
        {
            if (userID != null)
            {
                Models.User         myModel = new Models.User();
                CodeFirst.CodeFirst db      = new CodeFirst.CodeFirst();
                var intUserID = Int32.Parse(userID);
                var myUser    = db.Users.Where(i => i.UserID == intUserID).FirstOrDefault();

                var    stream = Request.InputStream;
                string dump;

                using (var reader = new StreamReader(stream))
                    dump = reader.ReadToEnd();

                var path = Server.MapPath("~/Files/" + myUser.FirstName + myUser.UserID + ".jpg");
                System.IO.File.WriteAllBytes(path, String_To_Bytes2(dump));

                myUser.UserPicture = "~/Files/" + myUser.FirstName + myUser.UserID + ".jpg";

                db.SaveChanges();
            }
            else
            {
            }
        }
コード例 #14
0
        public ActionResult Modify([Bind(Prefix = "")] Models.Project model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var myProject = db.Projects.Where(v => v.ProjectID == model.ProjectID).SingleOrDefault();

                if (myProject != null)
                {
                    myProject.ProjectID          = model.ProjectID;
                    myProject.ProjectName        = model.ProjectName;
                    myProject.StartDate          = model.StartDate;
                    myProject.Finished           = model.Finished;
                    myProject.ExpectedFinishDate = model.ExpectedFinishDate;
                    myProject.ProjectDescription = model.ProjectDescription;
                    myProject.TypeID             = model.TypeID;
                    myProject.UserID             = model.UserID;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "Project"));
            }

            model.ProjectTypes = db.Project_Type.ToList();
            model.Users        = db.Users.AsEnumerable().Select(u => new SelectListItem
            {
                Value = u.UserID.ToString(),
                Text  = u.Initials + " " + u.LastName
            }).ToList();
            return(View("Index", model));
        }
コード例 #15
0
        public ActionResult Create([Bind(Prefix = "")] Models.AccessLevel model)
        {
            if (ModelState.IsValid)
            {
                var db = new CodeFirst.CodeFirst();
                if (db.Access_Level.Count() > 0)
                {
                    var item = db.Access_Level.OrderByDescending(a => a.AccessLevelID).FirstOrDefault();

                    db.Access_Level.Add(new CodeFirst.Access_Level
                    {
                        AccessLevelID    = item.AccessLevelID + 1,
                        LevelName        = model.LevelName,
                        LevelDescription = model.LevelDescription
                    });
                }
                else
                {
                    db.Access_Level.Add(new CodeFirst.Access_Level
                    {
                        AccessLevelID    = 1,
                        LevelName        = model.LevelName,
                        LevelDescription = model.LevelDescription
                    });
                }

                db.SaveChanges();
                model.JavaScriptToRun = "mySuccess()";
                TempData["model"]     = model;
                return(RedirectToAction("Index", "AccessLevels"));
            }

            return(View("Index", model));
        }
コード例 #16
0
        public ActionResult Create([Bind(Prefix = "")] Models.QuantityType model)
        {
            if (ModelState.IsValid)
            {
                var db = new CodeFirst.CodeFirst();
                if (db.Quantity_Type.Count() > 0)
                {
                    var item = db.Quantity_Type.OrderByDescending(a => a.QuantityTypeID).FirstOrDefault();

                    db.Quantity_Type.Add(new CodeFirst.Quantity_Type
                    {
                        QuantityTypeID = item.QuantityTypeID + 1,
                        Description    = model.Description
                    });
                }
                else
                {
                    db.Quantity_Type.Add(new CodeFirst.Quantity_Type
                    {
                        QuantityTypeID = 1,
                        Description    = model.Description
                    });
                }

                db.SaveChanges();
                model.JavaScriptToRun = "mySuccess()";
                TempData["model"]     = model;
                return(RedirectToAction("Index", "QuantityType"));
            }

            return(View("Index", model));
        }
コード例 #17
0
        public ActionResult Modify([Bind(Prefix = "")] Models.Supplier model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var Supplier = db.Suppliers.Where(v => v.SupplierID == model.SupplierID).SingleOrDefault();

                if (Supplier != null)
                {
                    Supplier.SupplierID    = model.SupplierID;
                    Supplier.Name          = model.Name;
                    Supplier.VATNumber     = model.VATNumber;
                    Supplier.EmailAddress  = model.EmailAddress;
                    Supplier.ContactNumber = model.ContactNumber;
                    Supplier.Bank          = model.Bank;
                    Supplier.AccountNumber = model.AccountNumber;
                    Supplier.BranchCode    = model.BranchCode;
                    Supplier.POAddress     = model.POAddress;
                    Supplier.POCity        = model.POCity;
                    Supplier.POAreaCode    = model.POAreaCode;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "Supplier"));
            }

            return(View("Index", model));
        }
コード例 #18
0
        public ActionResult Modify([Bind(Prefix = "")] Models.Donor_Org model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var DonorOrg = db.Donor_Org.Where(v => v.DonorOrgID == model.DonorOrgID).SingleOrDefault();

                if (DonorOrg != null)
                {
                    DonorOrg.DonorOrgID    = model.DonorOrgID;
                    DonorOrg.OrgName       = model.OrgName;
                    DonorOrg.ContactNum    = model.ContactNum;
                    DonorOrg.ContactEmail  = model.ContactEmail;
                    DonorOrg.Thanked       = model.Thanked;
                    DonorOrg.StreetAddress = model.StreetAddress;
                    DonorOrg.City          = model.City;
                    DonorOrg.AreaCode      = model.AreaCode;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "DonorOrg"));
            }

            return(View("Index", model));
        }
コード例 #19
0
        public ActionResult Create([Bind(Prefix = "")] Models.SoftwareLicenses model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                if (db.Software_Licenses.Count() > 0)
                {
                    var item = db.Software_Licenses.OrderByDescending(a => a.LicenceID).FirstOrDefault();

                    db.Software_Licenses.Add(new CodeFirst.Software_Licenses
                    {
                        LicenceID                = item.LicenceID + 1,
                        SoftwareName             = model.SoftwareName,
                        ActivationPeriodInMonths = model.ActivationPeriodInMonths
                    });
                }
                else
                {
                    db.Software_Licenses.Add(new CodeFirst.Software_Licenses
                    {
                        LicenceID                = 1,
                        SoftwareName             = model.SoftwareName,
                        ActivationPeriodInMonths = model.ActivationPeriodInMonths
                    });
                }

                db.SaveChanges();
                model.JavaScriptToRun = "mySuccess()";
                TempData["model"]     = model;
                return(RedirectToAction("Index", "SoftwareLicenses"));
            }

            return(View("Index", model));
        }
コード例 #20
0
        public ActionResult Upload([Bind(Prefix = "")] Models.EFTR model, HttpPostedFileBase file)
        {
            var db = new CodeFirst.CodeFirst();

            //array of allowed extensions
            var allowedExtensions = new[] { ".pdf" };
            //checking extension of file uploaded
            var checkExtension = Path.GetExtension(file.FileName).ToLower();
            //check if does not contain the extension (not png/jpg/jpeg)
            var myReq = db.EFT_Requisition.Where(v => v.RequisitionID == model.RequisitionID).SingleOrDefault();

            if (!allowedExtensions.Contains(checkExtension))
            {
                ViewBag.Error = "Only PDF Files are allowed.";
                return(View("Index", model));
            }
            if (file.ContentLength > 8 * 1024 * 1024)
            {
                ViewBag.Error = "File too big!";
            }
            if (ViewBag.Error == null)
            {
                if (myReq != null)
                {
                    string path = Path.Combine(Server.MapPath("~/Files"), Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                    myReq.ReceiptFile = "~/Files/" + file.FileName;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "EFTR"));
            }
            return(View("Index", model));
        }
コード例 #21
0
        public ActionResult Modify([Bind(Prefix = "")] Models.Funder_Org model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var myFunderOrg = db.Funder_Org.Where(v => v.FunderOrgID == model.FunderOrgID).SingleOrDefault();

                if (myFunderOrg != null)
                {
                    myFunderOrg.FunderOrgID   = model.FunderOrgID;
                    myFunderOrg.OrgName       = model.OrgName;
                    myFunderOrg.ContactNumber = model.ContactNumber;
                    myFunderOrg.EmailAddress  = model.EmailAddress;
                    myFunderOrg.Bank          = model.Bank;
                    myFunderOrg.AccountNumber = model.AccountNumber;
                    myFunderOrg.BranchCode    = model.BranchCode;
                    myFunderOrg.StreetAddress = model.StreetAddress;
                    myFunderOrg.City          = model.City;
                    myFunderOrg.AreaCode      = model.AreaCode;
                    myFunderOrg.Thanked       = model.Thanked;
                    myFunderOrg.TypeID        = model.TypeID;
                    myFunderOrg.ProjectID     = model.ProjectID;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "FunderOrg"));
            }

            return(View("Index", model));
        }
コード例 #22
0
        public ActionResult Modify([Bind(Prefix = "")] Models.DonationItem model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var myDonationItem = db.Donation_Item.Where(v => v.DonationItemID == model.DonationItemID).SingleOrDefault();

                if (myDonationItem != null)
                {
                    myDonationItem.DonationItemID = model.DonationItemID;
                    myDonationItem.Description    = model.Description;
                    myDonationItem.TotalAmount    = model.TotalAmount;
                    myDonationItem.TypeID         = model.TypeID;
                    myDonationItem.QuantityTypeID = model.QuantityTypeID;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "DonationItem"));
            }

            model.DonationTypes = db.Donation_Type.ToList();
            model.QuantityTypes = db.Quantity_Type.ToList();
            return(View("Index", model));
        }
コード例 #23
0
        public ActionResult Modify([Bind(Prefix = "")] Models.RepairPerson model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var person = db.RepairPersons.Where(v => v.RepPersonID == model.RepPersonID).SingleOrDefault();

                if (person != null)
                {
                    person.RepPersonID   = model.RepPersonID;
                    person.Name          = model.Name;
                    person.EmailAddress  = model.EmailAddress;
                    person.Bank          = model.Bank;
                    person.AccountNumber = model.AccountNumber;
                    person.BranchCode    = model.BranchCode;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "RepairPersons"));
            }

            return(View("Index", model));
        }
コード例 #24
0
        public ActionResult Modify(string RequisitionID, string SupplierID, int UserID, int ProjectID, DateTime Date, Models.EFTRLine[] pcrdetails)
        {
            try
            {
                string  result = "information is incomplete.";
                int     LineID = 1;
                decimal Sum    = 0;
                if (pcrdetails != null && SupplierID != null && UserID != 0 && ProjectID != 0)
                {
                    var db       = new CodeFirst.CodeFirst();
                    var intReqID = Int32.Parse(RequisitionID);
                    var myEFTR   = db.EFT_Requisition.Where(a => a.RequisitionID == intReqID).FirstOrDefault();

                    myEFTR.RequisitionID = intReqID;
                    myEFTR.Date          = Date;
                    myEFTR.SupplierID    = Convert.ToInt32(SupplierID);
                    myEFTR.ProjectID     = ProjectID;
                    myEFTR.UserID        = UserID;

                    var lines = db.EFT_Requisition_Line.Where(p => p.RequisitionID == intReqID);
                    db.EFT_Requisition_Line.RemoveRange(lines);
                    //OrderLine
                    foreach (var item in pcrdetails)
                    {
                        var myItem = new CodeFirst.EFT_Requisition_Line();
                        myItem.RequisitionID = (int)myEFTR.RequisitionID;
                        myItem.LineID        = LineID;
                        myItem.Details       = item.Details;
                        myItem.QuantityEFT   = (int)item.QuantityEFT;
                        myItem.UnitPriceEFT  = (decimal)item.UnitPriceEFT;
                        myItem.TotalEFT      = decimal.Parse(item.TotalEFT.ToString().Substring(1, item.TotalEFT.ToString().Length - 1));
                        myItem.SupplierID    = Convert.ToInt32(SupplierID);

                        Sum += decimal.Parse(item.TotalEFT.ToString().Substring(1, item.TotalEFT.ToString().Length - 1));
                        LineID++;
                        db.EFT_Requisition_Line.Add(myItem);
                    }

                    myEFTR.TotalAmount = Sum;

                    if (Sum > 2000)
                    {
                        db.SaveChanges();
                        result = "Success! EFT Requisition updated!";
                    }
                    else
                    {
                        result = "Total Amount is less than R2000. Only Petty Cash Requisitions can be under this amount.";
                    }
                }
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                var result = "Error has occured!";

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #25
0
        public ActionResult Modify(string DonationID, int?DonorPID, int?DonorOrgID, DateTime Date, inDonationItem[] pcrdetails)
        {
            try
            {
                string  result = "information is incomplete.";
                int     LineID = 1;
                decimal Sum    = 0;
                if (pcrdetails != null && DonationID != null && DonorPID != 0 || DonorOrgID != 0)
                {
                    var db            = new CodeFirst.CodeFirst();
                    var intDonationID = Int32.Parse(DonationID);
                    db.Configuration.LazyLoadingEnabled = true;
                    var myDonation = db.Donations.Where(a => a.DonationID == intDonationID).FirstOrDefault();

                    myDonation.DonationID = intDonationID;
                    myDonation.DateDate   = Date;
                    myDonation.DonorPID   = DonorPID;
                    myDonation.DonorOrgID = DonorOrgID;

                    foreach (var item in db.Donation_Line.Where(d => d.DonationID == intDonationID))
                    {
                        var forTotal = db.Donation_Item.Where(d => d.DonationItemID == item.DonationItemID).FirstOrDefault();
                        forTotal.TotalAmount -= item.DonationAmount;
                    }

                    //OrderLine
                    foreach (var item in pcrdetails)
                    {
                        var myItem = new CodeFirst.Donation_Line();
                        myItem.DonationID  = (int)myDonation.DonationID;
                        myItem.LineID      = LineID;
                        myItem.Description = item.Description;

                        myItem.DonationItemID = db.Donation_Item.Where(d => d.TypeID == db.Donation_Type.Where(d2 => d2.TypeName == item.ItemType).FirstOrDefault().TypeID).FirstOrDefault().DonationItemID;;
                        myItem.DonationAmount = item.DonationAmount;

                        var forTotal = db.Donation_Item.Where(di => di.DonationItemID == myItem.DonationItemID).FirstOrDefault();
                        forTotal.TotalAmount += item.DonationAmount;

                        LineID++;
                        db.Donation_Line.Add(myItem);
                    }

                    db.Donation_Line.RemoveRange(db.Donation_Line.Where(d => d.DonationID == myDonation.DonationID));

                    db.SaveChanges();
                    result = "Success! Donation updated!";
                }
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception error)
            {
                var result = "Error has occured!";

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #26
0
        public ActionResult Create([Bind(Prefix = "")] Models.Funder_Org model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                if (db.Funder_Org.Count() > 0)
                {
                    var item = db.Funder_Org.OrderByDescending(a => a.FunderOrgID).FirstOrDefault();

                    db.Funder_Org.Add(new CodeFirst.Funder_Org
                    {
                        FunderOrgID   = item.FunderOrgID + 1,
                        OrgName       = model.OrgName,
                        ContactNumber = model.ContactNumber,
                        EmailAddress  = model.EmailAddress,
                        Bank          = model.Bank,
                        AccountNumber = model.AccountNumber,
                        BranchCode    = model.BranchCode,
                        StreetAddress = model.StreetAddress,
                        City          = model.City,
                        AreaCode      = model.AreaCode,
                        Thanked       = false,
                        TypeID        = model.TypeID,
                        ProjectID     = model.ProjectID,
                    });
                }
                else
                {
                    db.Funder_Org.Add(new CodeFirst.Funder_Org
                    {
                        FunderOrgID   = 1,
                        OrgName       = model.OrgName,
                        ContactNumber = model.ContactNumber,
                        EmailAddress  = model.EmailAddress,
                        Bank          = model.Bank,
                        AccountNumber = model.AccountNumber,
                        BranchCode    = model.BranchCode,
                        StreetAddress = model.StreetAddress,
                        City          = model.City,
                        AreaCode      = model.AreaCode,
                        Thanked       = false,
                        TypeID        = model.TypeID,
                        ProjectID     = model.ProjectID,
                    });
                }

                db.SaveChanges();
                model.JavaScriptToRun = "mySuccess()";
                TempData["model"]     = model;
                return(RedirectToAction("Index", "FunderOrg"));
            }

            model.FunderTypes = db.Funder_Type.ToList();
            model.Project     = db.Projects.ToList();
            return(View("Index", model));
        }
コード例 #27
0
        public ActionResult Create([Bind(Prefix = "")] Models.Equipment model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                if (db.Equipments.Count() > 0)
                {
                    var item = db.Equipments.OrderByDescending(a => a.EquipmentID).FirstOrDefault();

                    db.Equipments.Add(new CodeFirst.Equipment
                    {
                        EquipmentID           = item.EquipmentID + 1,
                        ManufacturerName      = model.ManufacturerName,
                        ModelNumber           = model.ModelNumber,
                        DatePurchased         = DateTime.ParseExact(model.DatePurchased.ToString("dd-MM-yyyy"), "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture),
                        ServiceIntervalMonths = model.ServiceIntervalMonths,
                        Status = model.Status,
                        UserID = model.UserID,
                        TypeID = model.TypeID
                    });
                }
                else
                {
                    db.Equipments.Add(new CodeFirst.Equipment
                    {
                        EquipmentID           = 1,
                        ManufacturerName      = model.ManufacturerName,
                        ModelNumber           = model.ModelNumber,
                        DatePurchased         = DateTime.ParseExact(model.DatePurchased.ToString("dd-MM-yyyy"), "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture),
                        ServiceIntervalMonths = model.ServiceIntervalMonths,
                        Status = model.Status,
                        UserID = model.UserID,
                        TypeID = model.TypeID
                    });
                }

                db.SaveChanges();
                model.JavaScriptToRun = "mySuccess()";
                TempData["model"]     = model;
                return(RedirectToAction("Index", "Equipments"));
            }

            var users = db.Users
                        .AsEnumerable()
                        .Select(u => new SelectListItem
            {
                Value = u.UserID.ToString(),
                Text  = u.FirstName + " " + u.LastName
            }).ToList();

            model.Users          = users;
            model.EquipmentTypes = db.Equipment_Type.ToList();
            return(View("Index", model));
        }
コード例 #28
0
        public JsonResult Assign(Data data)
        {
            var db = new CodeFirst.CodeFirst();

            var myDonationLine = db.Donation_Line.Where(d => d.DonationID == data.donationID && d.LineID == data.lineID).FirstOrDefault();

            myDonationLine.ProjectID = GlobalProjectID;

            db.SaveChanges();
            return(Json(new { Url = "/Donation" }));
        }
コード例 #29
0
        public ActionResult Create([Bind(Prefix = "")] Models.Vehicle model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                if (db.Vehicles.Count() > 0)
                {
                    var item = db.Vehicles.OrderByDescending(a => a.VehicleID).FirstOrDefault();

                    db.Vehicles.Add(new Vehicle
                    {
                        VehicleID               = item.VehicleID + 1,
                        Brand                   = model.Brand,
                        Model                   = model.Model,
                        NumberPlate             = model.NumberPlate,
                        DateOfPurchase          = model.DateofPurchase,
                        DateofLastRepair        = model.DateofLastRepair,
                        DateofLicencePurchase   = model.DateofLicencePurchase,
                        LicenseExpireDate       = DateTime.ParseExact(model.LicenseExpireDate.Value.ToString("MM/dd/yyyy"), "MM/dd/yyyy", CultureInfo.InvariantCulture),
                        ServiceIntervalInMonths = model.ServiceIntervalInMonths,
                        ServiceIntervalInKMs    = model.ServiceIntervalInKMs,
                        TypeID                  = model.TypeID
                    });
                }
                else
                {
                    db.Vehicles.Add(new Vehicle
                    {
                        VehicleID               = 1,
                        Brand                   = model.Brand,
                        Model                   = model.Model,
                        NumberPlate             = model.NumberPlate,
                        DateOfPurchase          = model.DateofPurchase,
                        DateofLastRepair        = model.DateofLastRepair,
                        DateofLicencePurchase   = model.DateofLicencePurchase,
                        LicenseExpireDate       = model.LicenseExpireDate,
                        ServiceIntervalInMonths = model.ServiceIntervalInMonths,
                        ServiceIntervalInKMs    = model.ServiceIntervalInKMs,
                        TypeID                  = model.TypeID
                    });
                }

                db.SaveChanges();
                model.JavaScriptToRun = "mySuccess()";
                TempData["model"]     = model;
                return(RedirectToAction("Index", "Vehicles"));
            }

            model.VehicleTypes = db.Vehicle_Type.ToList();
            return(View("Index", model));
        }
コード例 #30
0
        public ActionResult Create([Bind(Prefix = "")] Models.Building model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                if (db.Buildings.Count() > 0)
                {
                    var item = db.Buildings.OrderByDescending(a => a.BuildingID).FirstOrDefault();

                    db.Buildings.Add(new CodeFirst.Building
                    {
                        BuildingID    = item.BuildingID + 1,
                        Name          = model.Name,
                        StreetAddress = model.StreetAddress,
                        City          = model.City,
                        AreaCode      = model.AreaCode
                    });
                }
                else
                {
                    db.Buildings.Add(new CodeFirst.Building
                    {
                        BuildingID    = 1,
                        Name          = model.Name,
                        StreetAddress = model.StreetAddress,
                        City          = model.City,
                        AreaCode      = model.AreaCode
                    });
                }

                db.SaveChanges();

                /*if (Request.Form["Referrer"] == "AddEquipment")
                 * {
                 *  //TempData["EquipmentModel"] = equipmentModelToPassBack;
                 *  return RedirectToAction("Index", "AddEquipment");
                 * }
                 * else
                 * {
                 *  model.JavaScriptToRun = "mySuccess()";
                 *  TempData["model"] = model;
                 *  return RedirectToAction("Index", "EquipmentType");
                 * }*/

                model.JavaScriptToRun = "mySuccess()";
                TempData["model"]     = model;
                return(RedirectToAction("Index", "Buildings"));
            }

            return(View("Index", model));
        }