Пример #1
0
        public ActionResult Add()
        {
            DailyHours d = new DailyHours();

            d.getNames();
            return(View(d));
        }
Пример #2
0
        /// <summary>
        ///
        /// Creates new Locations, Contacts, SpecialQualities, DailyHours.
        ///
        /// </summary>
        ///
        ///
        /// <param name="newLocation"> ViewModel with properties corresponding to the fields for each table </param>
        ///
        ///
        /// <returns>
        ///
        /// False: If newLocation is null or there was an error when attempting to insert
        /// True: It newLocation is successfully inserted into the Database
        ///
        /// </returns>
        public virtual bool Create(AllTablesViewModel newLocation)
        {
            if (newLocation == null) // Non-valid ViewModel Object
            {
                return(false);
            }

            // Ensures we don't end up with any duplicate LocationIds
            while (db.LocationIdNotUnique(newLocation.LocationId))
            {
                newLocation.LocationId = Guid.NewGuid().ToString();
            }



            Locations        location       = AllTablesViewModel.GetNewLocation(newLocation);
            Contacts         contact        = AllTablesViewModel.GetNewContact(newLocation);
            SpecialQualities specialQuality = AllTablesViewModel.GetNewSpecialQualities(newLocation);
            DailyHours       dailyHours     = AllTablesViewModel.GetNewDailyHours(newLocation);



            try
            {
                db.AlterRecordInfo(AlterRecordInfoEnum.Create, location);

                if (contact != null)
                {
                    db.AlterRecordInfo(AlterRecordInfoEnum.Create, contact);
                }


                if (specialQuality != null)
                {
                    db.AlterRecordInfo(AlterRecordInfoEnum.Create, specialQuality);
                }



                if (dailyHours != null)
                {
                    db.AlterRecordInfo(AlterRecordInfoEnum.Create, dailyHours);
                }


                db.SaveChanges();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
        public ActionResult Add(DailyHours h)
        {
            //if (ModelState.IsValid)
            /// {
            h.InsertDailyhours(h);
            ModelState.Clear();
            DailyHours d = new DailyHours();

            d.getNames();
            return(View(d));
            // }
            // else
            //     return View(h);
        }
        /// <summary>
        /// Populates a DailyHours Object from a View Model Object's properties.
        /// </summary>
        ///
        ///
        /// <param name="newLocation"> A View Model Object from which to extract from </param>
        ///
        ///
        /// <returns> A DailyHours Object or null if all properties are null </returns>
        public static DailyHours GetNewDailyHours(AllTablesViewModel newLocation)
        {
            if (newLocation is null)
            {
                return(null);
            }


            DailyHours dailyHours = new DailyHours();

            dailyHours.LocationId      = newLocation.LocationId;
            dailyHours.HoursDtfriClose = newLocation.HoursDtfriClose;
            dailyHours.HoursDtfriOpen  = newLocation.HoursDtfriOpen;
            dailyHours.HoursDtmonClose = newLocation.HoursDtmonClose;
            dailyHours.HoursDtmonOpen  = newLocation.HoursDtmonOpen;
            dailyHours.HoursDtsatClose = newLocation.HoursDtsatClose;
            dailyHours.HoursDtsatOpen  = newLocation.HoursDtsatOpen;
            dailyHours.HoursDtsunClose = newLocation.HoursDtsunClose;
            dailyHours.HoursDtsunOpen  = newLocation.HoursDtsunOpen;
            dailyHours.HoursDtthuClose = newLocation.HoursDtthuClose;
            dailyHours.HoursDtthuOpen  = newLocation.HoursDtthuOpen;
            dailyHours.HoursDttueClose = newLocation.HoursDttueClose;
            dailyHours.HoursDttueOpen  = newLocation.HoursDttueOpen;
            dailyHours.HoursDtwedClose = newLocation.HoursDtwedClose;
            dailyHours.HoursDtwedOpen  = newLocation.HoursDtwedOpen;
            dailyHours.HoursFriClose   = newLocation.HoursFriClose;
            dailyHours.HoursFriOpen    = newLocation.HoursFriOpen;
            dailyHours.HoursMonClose   = newLocation.HoursMonClose;
            dailyHours.HoursMonOpen    = newLocation.HoursMonOpen;
            dailyHours.HoursSatClose   = newLocation.HoursSatClose;
            dailyHours.HoursSatOpen    = newLocation.HoursSatOpen;
            dailyHours.HoursSunClose   = newLocation.HoursSunClose;
            dailyHours.HoursSunOpen    = newLocation.HoursSunOpen;
            dailyHours.HoursThuClose   = newLocation.HoursThuClose;
            dailyHours.HoursThuOpen    = newLocation.HoursThuOpen;
            dailyHours.HoursTueClose   = newLocation.HoursTueClose;
            dailyHours.HoursTueOpen    = newLocation.HoursTueOpen;
            dailyHours.HoursWedClose   = newLocation.HoursWedClose;
            dailyHours.HoursWedOpen    = newLocation.HoursWedOpen;


            if (dailyHours.AllPropertiesAreNull())
            {
                return(null);
            }


            return(dailyHours);
        }
Пример #5
0
        public ActionResult Edit(int staffId)
        {
            if (staffId < 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (staffId < 0)
            {
                return(HttpNotFound());
            }
            ModelState.Clear();
            DailyHours d = new DailyHours();

            d.getData(staffId);
            return(View(d));
        }
Пример #6
0
        public ActionResult Add(DailyHours h)
        {
            if (h == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (h == null)
            {
                return(HttpNotFound());
            }
            h.InsertDailyhours(h);
            ModelState.Clear();
            DailyHours d = new DailyHours();

            d.getNames();
            return(View(d));
        }
        public void DailyHours_Default_Should_Pass()
        {
            // Arrange
            var result = new DailyHours();

            // Act


            //Assert
            Assert.IsNotNull(result);                                       // DailyHours object exists

            PropertyInfo[] properties = typeof(DailyHours).GetProperties(); // All properties of DailyHours is null by default
            foreach (PropertyInfo property in properties)
            {
                var actual = property.GetValue(result);
                Assert.IsNull(actual);
            }
        }
 public ActionResult Edit(DailyHours d, string command)
 {
     if (command.Equals("Update"))
     {
         // if (ModelState.IsValid)
         //{
         d.UpdateDailyHours(d);
         // }
         //  else
         //{
         //   return View(d);
         //  }
     }
     else
     {
         d.DeleteDailyHours(d);
     }
     return(RedirectToAction("Details"));
 }
Пример #9
0
 public ActionResult Edit(DailyHours d, string command)
 {
     if (d == null || string.IsNullOrEmpty(command))
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     if (d == null || string.IsNullOrEmpty(command))
     {
         return(HttpNotFound());
     }
     if (command.Equals("Update"))
     {
         d.UpdateDailyHours(d);
     }
     else
     {
         d.DeleteDailyHours(d);
     }
     return(RedirectToAction("Details"));
 }
        public void DailyHours_Set_Properties_Should_Pass()
        {
            // Arrange
            var result = new DailyHours();

            // Act
            PropertyInfo[] properties = typeof(DailyHours).GetProperties();
            foreach (PropertyInfo property in properties)
            {
                if (property.PropertyType.Name.Equals("Locations"))
                {
                    property.SetValue(result, new Locations());
                }

                else
                {
                    property.SetValue(result, property.Name);
                }
            }



            //Assert
            Assert.IsNotNull(result);   // DailyHours object exists

            foreach (PropertyInfo property in properties)
            {
                if (property.PropertyType.Name.Equals("Locations"))
                {
                    Assert.AreEqual("Locations", property.PropertyType.Name);
                }


                else
                {
                    var expected = property.Name;
                    var actual   = property.GetValue(result);
                    Assert.AreEqual(expected, actual);
                }
            }
        }