Пример #1
0
        /// <summary>
        /// Converts centimeters (as stored in decimal form in the database) to feet and inches
        /// </summary>
        /// <param name="obj">The physiology object to modify</param>
        private void ConvertToFeetAndInches(PhysiologyDto obj)
        {
            int totalInches = Convert.ToInt32(obj.Height.GetValueOrDefault() * InchesPerCentimeter);

            obj.Feet   = totalInches / 12;
            obj.Inches = totalInches % 12;
        }
Пример #2
0
        /// <summary>
        /// Modifies a physiology record in the database
        /// </summary>
        /// <param name="physiology">The physiology dto model to save</param>
        public void Edit(PhysiologyDto physiology)
        {
            var phy = PhysiologyToDomain(physiology);

            db.Entry(phy).State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #3
0
        /// <summary>
        /// Finds a specific physiology record and adds and adjusts relating properties for display
        /// </summary>
        /// <param name="phyId">The identifier for a physiology record</param>
        /// <returns>The specified physiology dto model</returns>
        public PhysiologyDto FindPhysiologyRecord(int phyId)
        {
            Physiology    physiology = db.Physiologies.Find(phyId);
            PhysiologyDto model      = new PhysiologyDto()
            {
                Height      = physiology.Height,
                Weight      = physiology.Weight,
                Date        = physiology.Date,
                IsLosing    = physiology.IsLosing,
                PhyId       = phyId,
                Comment     = physiology.Comment,
                AgeSnapshot = physiology.AgeSnapshot,
                UserId      = (from u in this.db.User_Phy
                               where u.PhyId == phyId
                               select u.UserId).FirstOrDefault(),
            };

            if (model.Comment == null)
            {
                model.Comment = "";
            }

            ConvertToFeetAndInches(model);

            return(model);
        }
        /// <summary>
        /// The details of a specific physiology record
        /// </summary>
        /// <param name="id">The identifier of a specific physiology record</param>
        /// <param name="page">The page name/source</param>
        /// <returns>The details view</returns>
        // GET: Physiologies/Details/5
        public ActionResult Details(int id, string page)
        {
            PhysiologyServices phyService = new PhysiologyServices();
            PhysiologyDto      model      = phyService.FindPhysiologyRecord(id);

            model.Page = page;
            return(View(model));
        }
        public ActionResult Create(PhysiologyDto physiology)
        {
            if (ModelState.IsValid)
            {
                PhysiologyServices service = new PhysiologyServices();
                service.SaveCreate(physiology);
                return(RedirectToAction("GetUserPage", "Users", new { page = physiology.Page }));
            }

            return(View(physiology));
        }
        /// <summary>
        /// Renders the delete view
        /// </summary>
        /// <param name="id">The id of the physiology record to display</param>
        /// <param name="page">The page name/source</param>
        /// <returns>The delete view</returns>
        // GET: Physiologies/Delete/5
        public ActionResult Delete(int id, string page)
        {
            PhysiologyServices service  = new PhysiologyServices();
            PhysiologyDto      phyModel = service.FindPhysiologyRecord(id);

            if (phyModel == null)
            {
                return(HttpNotFound());
            }
            phyModel.Page = page;
            return(View(phyModel));
        }
 public ActionResult Edit(PhysiologyDto physiology)
 {
     if (ModelState.IsValid)
     {
         PhysiologyServices service = new PhysiologyServices();
         service.Edit(physiology);
         if (physiology.Page == null)
         {
             return(RedirectToAction("Index", "Physiologies"));
         }
         return(RedirectToAction("GetUserPage", "Users", new { page = physiology.Page }));
     }
     return(View(physiology));
 }
Пример #8
0
        /// <summary>
        /// Transfers physiology dto model data into the domain model
        /// </summary>
        /// <param name="physiology">The physiology dto model</param>
        /// <returns>The physiology domain model</returns>
        private Physiology PhysiologyToDomain(PhysiologyDto physiology)
        {
            var phy = new Physiology
            {
                Height      = ConvertToCentimeters(physiology),
                Weight      = physiology.Weight,
                IsLosing    = physiology.IsLosing,
                Date        = physiology.Date,
                PhyId       = physiology.PhyId,
                Comment     = physiology.Comment,
                AgeSnapshot = physiology.AgeSnapshot
            };

            return(phy);
        }
        public ActionResult DeleteConfirmed(PhysiologyDto physiology)
        {
            PhysiologyServices service = new PhysiologyServices();

            if (!service.Delete(physiology.PhyId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (physiology.Page == null)
            {
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("GetUserPage", "Users", new { page = physiology.Page }));
        }
Пример #10
0
        /// <summary>
        /// Saves a newly created physiology record
        /// </summary>
        /// <param name="physiology">The physiology model</param>
        public void SaveCreate(PhysiologyDto physiology)
        {
            var phyDomain = PhysiologyToDomain(physiology);

            UserServices userService = new UserServices();
            UserDto      dto         = userService.GetUser();

            phyDomain.AgeSnapshot = userService.GetTimespanSinceBirthdate(dto.BirthDate);

            var domain = new User_Phy
            {
                UserId     = physiology.UserId,
                Physiology = phyDomain
            };

            db.User_Phy.Add(domain);
            db.SaveChanges();
        }
Пример #11
0
 /// <summary>
 /// Converts inches to centimeters for storing height (in decimal form)
 /// </summary>
 /// <param name="physiology">The physiology model</param>
 /// <returns>The converted value to centimeters</returns>
 public decimal ConvertToCentimeters(PhysiologyDto physiology)
 {
     return(Math.Round(((physiology.Feet * 12 + physiology.Inches) / InchesPerCentimeter), 2));
 }