示例#1
0
        public void UpdateTreatmentsInCategory(TreatmentCategory category)
        {
            int              categoryID = category.ID;
            string           name       = category.Name;
            List <Treatment> treatments = category.Treatments;

            foreach (Treatment t in treatments)
            {
                int treatmentID = t.ID;
                using (var conn = new SqlConnection(_connectionString))
                {
                    string checkString = "SELECT categoryID, treatmentID FROM CategoryOfTreatments WHERE (categoryID = @categoryID AND treatmentID = @treatmentID)";

                    var sqlSelectReader = conn.ExecuteReader(checkString, new { categoryID = categoryID, treatmentID = treatmentID });

                    if (!sqlSelectReader.Read())
                    {
                        sqlSelectReader.Close();
                        string queryString = "INSERT INTO CategoryOfTreatments (treatmentID, categoryID) VALUES (@treatmentID, @categoryID);";
                        conn.ExecuteReader(queryString, new
                        {
                            treatmentID,
                            categoryID
                        });
                    }
                }
            }
        }
示例#2
0
        public IActionResult Put([FromODataUri] Guid key, TreatmentCategory treatmentcategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var trans = context.Database.BeginTransaction())
            {
                try
                {
                    if (context.TreatmentCategories.Find(key) == null)
                    {
                        return(NotFound());
                    }
                    //context = new ApplicationDbContext(context.Options);
                    var local = context.TreatmentCategories.Local.FirstOrDefault(it => it.TreatmentCategoryID.Equals(key));
                    if (local != null)
                    {
                        context.Entry(local).State = EntityState.Detached;
                    }


                    context.Entry(treatmentcategory).State = EntityState.Modified;
                    context.SaveChanges();
                    trans.Commit();
                    return(Ok(treatmentcategory));
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    return(BadRequest(ex));
                }
            }
        }
示例#3
0
 public Treatment(string name, TimeSpan duration, TreatmentCategory category, double price)
 {
     Name     = name;
     Duration = duration;
     Category = category;
     Price    = price;
 }
示例#4
0
 public void DeleteCategory(TreatmentCategory category)
 {
     if (category != null)
     {
         _context.Entry(category).State = EntityState.Deleted;
         _context.TreatmentCategories.Remove(category);
         _context.SaveChanges();
     }
 }
示例#5
0
 public void CreateCategory(TreatmentCategory category)
 {
     if (category != null)
     {
         _context.Entry(category).State = EntityState.Added;
         _context.TreatmentCategories.Add(category);
         _context.SaveChanges();
     }
 }
        public ActionResult Save(TreatmentCategoryEditItem treatmentCategory)
        {
            if (ModelState.IsValid)
            {
                if (!FileHelper.ValidateIfImage(ControllerContext.HttpContext.Request.Files))
                {
                    ModelState.AddModelError(string.Empty, $"Input image should be in ({ConfigurationManager.AllowedImageFormats}) formats only.");
                    return(View("TreatmentCategoryEditView", treatmentCategory));
                }

                var oldPictureUrl = treatmentCategory.PictureUrl;

                var newTreatmentCategory = new TreatmentCategory
                {
                    Id          = treatmentCategory.Id,
                    Name        = treatmentCategory.Name,
                    Description = treatmentCategory.Description,
                    IsActive    = treatmentCategory.IsActive
                };

                bool hasError = false;
                try
                {
                    if (ControllerContext.HttpContext.Request.Files.Count > 0 &&
                        ControllerContext.HttpContext.Request.Files[0] != null &&
                        ControllerContext.HttpContext.Request.Files[0].ContentLength > 0)
                    // new file posted. Remove old one.
                    {
                        newTreatmentCategory.PictureUrl = FileHelper.SaveFile(ControllerContext);
                        FileHelper.DeleteFile(oldPictureUrl);
                    }
                    else
                    {
                        newTreatmentCategory.PictureUrl = treatmentCategory.PictureUrl;
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, $"{ex.Message}");
                    hasError = true;
                }

                Manager.CreateOrUpdate(newTreatmentCategory);

                if (hasError)
                {
                    return(View("TreatmentCategoryEditView", treatmentCategory));
                }

                return(RedirectToAction("TreatmentCategoryList", "TreatmentCategory"));
            }

            return(View("TreatmentCategoryEditView", treatmentCategory));
        }
示例#7
0
        static bool Prefix(MentalStateHandler __instance, ref bool __result, MentalStateDef stateDef, string reason, bool forceWake, bool causedByMood, Pawn otherPawn)
        {
            if (!causedByMood)
            {
                return(true);
            }

            Pawn pawn = (Pawn)(typeof(MentalStateHandler).GetField("pawn", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance));

            if (pawn.IsPrisonerOfColony)
            {
                var need = pawn.needs.TryGetNeed <Need_Treatment>();
                if (need != null)
                {
                    TreatmentCategory treatmentCat = need.CurCategory;
                    bool  suspended = false;
                    float chance    = 0f;

                    switch (treatmentCat)
                    {
                    case TreatmentCategory.Normal:
                        chance = 0.1f;
                        break;

                    case TreatmentCategory.Bad:
                        chance = 0.5f;
                        break;

                    case TreatmentCategory.VeryBad:
                        chance = 1f;
                        break;
                    }

                    suspended = UnityEngine.Random.value < chance;

                    if (suspended)
                    {
                        __result = false;
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#8
0
        public int CreateOrUpdate(TreatmentCategory treatmentCategory)
        {
            if (treatmentCategory.Id == 0)
            {
                _context.TreatmentCategories.Add(treatmentCategory);
            }
            else
            {
                var oldTreatmentCategory = _context.TreatmentCategories
                                           .FirstOrDefault(c => c.Id == treatmentCategory.Id);

                oldTreatmentCategory.Name        = treatmentCategory.Name;
                oldTreatmentCategory.Description = treatmentCategory.Description;
                oldTreatmentCategory.PictureUrl  = treatmentCategory.PictureUrl;
                oldTreatmentCategory.IsActive    = treatmentCategory.IsActive;
            }

            _context.SaveChanges();

            return(treatmentCategory.Id);
        }
示例#9
0
        public IActionResult Post(TreatmentCategory treatmentcategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (var trans = context.Database.BeginTransaction())
            {
                try
                {
                    context.TreatmentCategories.Add(treatmentcategory);
                    context.SaveChanges();
                    trans.Commit();
                    return(Ok(treatmentcategory));
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    return(BadRequest(ex));
                }
            }
        }