Beispiel #1
0
 public ActionResult Edit(CareHome carehome)
 {
     if (ModelState.IsValid)
     {
         if (carehome.CareHomeId == 0)
         {
             // Add
             db.CareHomes.Add(carehome);
         }
         else
         {
             // Edit
             var entry = db.Entry(carehome);
             entry.State = EntityState.Modified;
             entry.Property(h => h.UserId).IsModified      = false;
             entry.Property(h => h.Rating).IsModified      = false;
             entry.Property(h => h.ReviewCount).IsModified = false;
             //db.Entry(carehome).Property(h => h.CareManagers).IsModified = false;
         }
         db.SaveChanges();
         Log(LogType.Admin, "事業所情報を更新しました。");
         return(RedirectToAction("Index"));
     }
     ViewBag.AreaId = new SelectList(db.Areas.Select(a => new { AreaId = a.AreaId, CityName = a.PrefectureName + a.CityName }), "AreaId", "CityName", carehome.AreaId);
     return(View(carehome));
 }
Beispiel #2
0
        public ActionResult EditAdditionalInfo(CareHome careHome, HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 200000)
            {
                ModelState.AddModelError("", "アップロードできる画像のサイズは200kBまでです。");
            }

            ModelState.Remove("CareHomeCode");

            if (ModelState.IsValid)
            {
                var home = db.CareHomes.Find(careHome.CareHomeId);
                home.Region   = careHome.Region;
                home.Traits   = careHome.Traits;
                home.Messages = careHome.Messages;

                if (file != null)
                {
                    BlobHelper.DeleteIfExists("mediafile", home.MediaFileDataId);
                    home.MediaFileDataId = BlobHelper.Upload("mediafile", file, file.FileName);
                }

                db.SaveChanges();

                Log(LogType.CareHome, "追加情報を更新しました。");
                Flash("保存しました。");
                return(RedirectToAction("CareHomeMenu", "Home"));
            }
            return(View(careHome));
        }
Beispiel #3
0
        public ActionResult Index(string code)
        {
            if (CurrentUser == null)
            {
                throw new Exception("会員情報が見つかりません。");
            }

            CareHome home = null;

            if (code == null)
            {
                home = CurrentUser.CareHomes.FirstOrDefault();
                if (home == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                return(RedirectToAction("Index", new { code = home.CareHomeCode }));
            }

            home = CurrentUser.CareHomes.FirstOrDefault(h => h.CareHomeCode == code);
            if (home == null)
            {
                return(HttpNotFound());
            }

            var careManagers = home.CareManagers.OrderBy(m => m.Order).ToList();

            return(View(new CareManagerIndexVM()
            {
                CareHomeId = home.CareHomeId,
                CareHomeCode = home.CareHomeCode,
                CareManagers = careManagers
            }));
        }
        //public async Task<IEnumerable<CareHome>> Task<CareHome> Add(CareHome newCareHome);(Boolean newCareHome)
        //{
        //    return await _context.CareHomes.AddAsync()
        //}

        public async Task <CareHome> AddAsync(CareHome newCareHome)
        {
            newCareHome.IsActive  = true;
            newCareHome.CreatedOn = DateTime.UtcNow;
            var careHome = await _context.CareHomes.AddAsync(newCareHome);

            await _context.SaveChangesAsync();

            return(newCareHome);
        }
Beispiel #5
0
        public ActionResult UpdateFromCsv(int skip = 0, int take = 500)
        {
            Log(LogType.Admin, string.Format("CSVからの更新を試みました。({0}行目から{1}行)", skip, take));

            var container = BlobHelper.GetContainer("csv");
            var blob      = container.GetBlockBlobReference("CareHome.UploadCsv");

            using (var mem = new MemoryStream())
            {
                blob.DownloadToStream(mem);
                mem.Seek(0, SeekOrigin.Begin);

                using (var reader = new System.IO.StreamReader(mem, System.Text.Encoding.GetEncoding("Shift_JIS")))
                    using (var csv = new CsvReader(reader))
                    {
                        for (var n = 0; n < skip; n++)
                        {
                            // Skips until the first line.
                            csv.Read();
                        }

                        var japaneseCalendarRegex = new Regex(@"^(?<jpyear>\d{4})-(?<month>\d{2})-(?<day>\d{2})$");
                        var added   = 0;
                        var updated = 0;
                        while ((added + updated) < take && csv.Read())
                        {
                            string code = null;
                            try
                            {
                                var row = csv.CurrentRecord;
                                if (row.Length != 44)
                                {
                                    return(Json(new { success = false, error = string.Format("列の数が正しくありません。行:{0} 必要な列数:{1} 実際の列数:{2}", skip + added + updated, 44, row.Length), added = added, updated = updated }));
                                }

                                Debug.WriteLine(row[0] + row[1]);

                                code = row[0]; // 事業所ID
                                var home = db.CareHomes.FirstOrDefault(h => h.CareHomeCode == code);
                                if (home == null)
                                {
                                    home = new CareHome()
                                    {
                                        CareHomeCode = code
                                    };
                                    db.CareHomes.Add(home);
                                    added++;
                                }
                                else
                                {
                                    updated++;
                                }

                                home.Name = csv.GetField <string>("事業所名");
                                home.Zip  = csv.GetField <string>("郵便番号");
                                // 都道府県 => city
                                // 市区町村 => city
                                home.Address         = csv.GetField <string>("番地");
                                home.AddressBuilding = csv.GetField <string>("建物名部屋番号等");
                                var cityCode = csv.GetField <int>("city");
                                home.Area       = db.Areas.First(a => a.CityCode == cityCode);
                                home.Longitude  = csv.GetField <double>("fX");
                                home.Latitude   = csv.GetField <double>("fY");
                                home.Tel        = csv.GetField <string>("Tel");
                                home.Fax        = csv.GetField <string>("Fax");
                                home.WebsiteUrl = csv.GetField <string>("ホームページ");
                                var match = japaneseCalendarRegex.Match(csv.GetField <string>("事業開始日"));
                                if (match.Success)
                                {
                                    // Japanese Calendar format like "0025-08-26".
                                    var year  = 1988 + int.Parse(match.Groups["jpyear"].ToString());
                                    var month = int.Parse(match.Groups["month"].ToString());
                                    var day   = int.Parse(match.Groups["day"].ToString());
                                    if (year == 1988 && month == 0 && day == 0)
                                    {
                                        home.Established = null;
                                    }
                                    else
                                    {
                                        home.Established = new DateTime(year, month, day);
                                    }
                                }
                                else
                                {
                                    home.Established = csv.GetField <DateTime>("事業開始日");
                                }
                                home.CompanyType   = (CompanyType)Enum.Parse(typeof(CompanyType), csv.GetField <string>("法人区分").Replace('・', '_').Replace('(', '_').Replace(')', '_'));
                                home.CompanyName   = csv.GetField <string>("法人名称");
                                home.ChiefName     = csv.GetField <string>("施設管理者氏名");
                                home.ChiefJobTitle = csv.GetField <string>("施設管理者職名");
                                match = japaneseCalendarRegex.Match(csv.GetField <string>("情報更新日"));
                                if (match.Success)
                                {
                                    // Japanese Calendar format like "0025-08-26".
                                    var year  = 1988 + int.Parse(match.Groups["jpyear"].ToString());
                                    var month = int.Parse(match.Groups["month"].ToString());
                                    var day   = int.Parse(match.Groups["day"].ToString());
                                    if (year == 1988 && month == 0 && day == 0)
                                    {
                                        home.DataUpdated = null;
                                    }
                                    else
                                    {
                                        home.DataUpdated = new DateTime(year, month, day);
                                    }
                                }
                                else
                                {
                                    home.DataUpdated = csv.GetField <DateTime>("情報更新日");
                                }
                                home.介護支援専門員在席人数 = csv.GetField <Nullable <double> >("介護支援専門員_合計");
                                home.介護支援専門員常勤換算 = csv.GetField <Nullable <double> >("介護支援専門員_常勤換算人数");
                                home.事務員在席人数     = csv.GetField <Nullable <double> >("事務員_合計");
                                home.事務員常勤換算     = csv.GetField <Nullable <double> >("事務員_常勤換算人数");
                                home.その他在席人数     = csv.GetField <Nullable <double> >("その他_合計");
                                home.その他常勤換算     = csv.GetField <Nullable <double> >("その他_常勤換算人数");
                                home.全職員在席人数     = csv.GetField <Nullable <double> >("全職員_合計");
                                home.全職員常勤換算     = csv.GetField <Nullable <double> >("全職員_常勤換算人数");
                                home.経験5年以上割合    = csv.GetField <Nullable <double> >("経験5年以上割合");
                                home.利用者数        = csv.GetField <Nullable <double> >("利用者数");
                                home.自立          = csv.GetField <Nullable <double> >("自立");
                                home.要介護5        = csv.GetField <Nullable <double> >("要介護5");
                                home.要介護4        = csv.GetField <Nullable <double> >("要介護4");
                                home.要介護3        = csv.GetField <Nullable <double> >("要介護3");
                                home.要介護2        = csv.GetField <Nullable <double> >("要介護2");
                                home.要介護1        = csv.GetField <Nullable <double> >("要介護1");
                                home.要支援2        = csv.GetField <Nullable <double> >("要支援2");
                                home.要支援1        = csv.GetField <Nullable <double> >("要支援1");
                                home.利用者の権利擁護    = csv.GetField <Nullable <double> >("利用者の権利擁護");
                                home.サービスの質の確保   = csv.GetField <Nullable <double> >("サービスの質の確保");
                                home.相談苦情等への対応   = csv.GetField <Nullable <double> >("相談・苦情等への対応");
                                home.外部機関等との連携   = csv.GetField <Nullable <double> >("外部機関等との連携");
                                home.事業運営管理      = csv.GetField <Nullable <double> >("事業運営・管理");
                                home.安全衛生管理等     = csv.GetField <Nullable <double> >("安全・衛生管理等");
                                home.従業者の研修等     = csv.GetField <Nullable <double> >("従業者の研修等");

                                db.Entry(home).Property(h => h.UserId).IsModified = false;
                                db.SaveChanges();
                            }
                            catch (Exception e)
                            {
                                return(Json(new { success = false, error = (skip + added + updated - 1) + "行目" + code + "の更新中にエラーが発生しました。" + e.ToString(), added = added, updated = updated }));
                            }
                        }

                        return(Json(new { success = true, error = "", added = added, updated = updated }));
                    }
            }
        }