Exemplo n.º 1
0
        protected override async Task OnPageInitializedAsync()
        {
            if (!IsAuthenticated)
            {
                Navi.NavigateTo("/login");
                return;
            }

            var list = await DiaryService.GetWritableDiaryInfoAsync(User);

            DiaryInfo = list.FirstOrDefault(x => x.DiaryName == DiaryName);

            if (DiaryInfo == null)
            {
                Navi.NavigateTo(DiaryUrl.Home(DiaryName));
            }

            if (DiaryInfo.IsSecret && string.IsNullOrWhiteSpace(UserData.Password))
            {
                Navi.NavigateTo(DiaryUrl.SetPassword());
                return;
            }

            LastDiary = await DiaryService.GetLastDiaryViewAsync(User, DiaryInfo);

            Date = DateTime.Today;
        }
Exemplo n.º 2
0
        public ActionResult Index(DiaryView entryView)
        {
            var user = context.Users.Include(u => u.Entries).FirstOrDefault(u => u.UserName == User.Identity.Name);

            if (ModelState.IsValid)
            {
                if (entryView.Weight.HasValue)
                {
                    context.WeightEntries.Add(new WeightEntry {
                        Date = entryView.Date, Weight = entryView.Weight.Value, User = user
                    });
                }

                if (entryView.FoodId.HasValue && entryView.Amount.HasValue)
                {
                    var d = entryView.Date;
                    d = d.AddHours(entryView.Time.Hour);
                    d = d.AddMinutes(entryView.Time.Minute);
                    var entry = new Entry
                    {
                        Date     = d, //TODO: Might not work
                        FoodId   = entryView.FoodId.Value,
                        Quantity = entryView.Amount.Value,
                        UnitId   = entryView.UnitId,
                        User     = user
                    };
                    context.Add(entry);
                }
                context.SaveChanges();
            }
            else
            {
                entryView.Entries = context.Entries
                                    .Include(e => e.Food)
                                    .ThenInclude(f => f.Meassures)
                                    .Where(e => e.UserId == user.Id && e.Date.Date == entryView.Date.Date)
                                    .OrderBy(e => e.Date).ToList();

                entryView.GroupedEntries = entryView.Entries
                                           .GroupBy(e =>
                {
                    var updated = e.Date.AddMinutes(30);
                    return(new DateTime(updated.Year, updated.Month, updated.Day,
                                        updated.Hour, 0, 0, e.Date.Kind));
                }).Select(cl => cl.ToList()).ToList();

                entryView.Foods = new List <FoodView>();

                return(View(entryView));
            }

            return(RedirectToRoute("diary", new { controller = "Diary", action = "Index", date = entryView.Date.ToString("yyyy-MM-dd") }));
        }
Exemplo n.º 3
0
        private bool IsMyText(DiaryView view)
        {
            if (view.DiaryInfo.Owner == User.Email)
            {
                return(true);
            }

            if (view.DiaryInfo.Writers?.Contains(User.Email) ?? false)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        protected void repeater_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            DiaryView log = e.Item.DataItem as DiaryView;

            if (log != null)
            {
                SmartLabel         selection = (SmartLabel)e.Item.FindControl("selection");
                NetRadio.Data.User oUser     = NetRadio.Data.User.SelectByUserName(me.Name);
                if (oUser.Role >= (int)UserRole.Admin)
                {
                    //selection.Text = "<input type='checkbox' name='selection' value='" + log.Id + "' />";
                }
                else
                {
                    //selection.Text = "-";
                }

                if (log.UserId != 0)
                {
                    SmartLabel userName = (SmartLabel)e.Item.FindControl("userName");
                    userName.Text = log.UserName;
                }

                SmartLabel description = (SmartLabel)e.Item.FindControl("description");
                description.Text = log.Action;

                //SmartLabel hostName = (SmartLabel)e.Item.FindControl("hostName");
                //hostName.Text = log.HostName;

                SmartLabel tagMac = (SmartLabel)e.Item.FindControl("tagMac");
                tagMac.Text = log.TagMac;

                DateTimeLabel writeTime = (DateTimeLabel)e.Item.FindControl("writeTime");
                writeTime.DisplayValue = log.WriteTime;
            }
        }
Exemplo n.º 5
0
 public static string NextDate(DiaryView view)
 {
     return(DiaryContent(view.DiaryInfo.DiaryName, view.DiaryNavigationData.NextDate.Value));
 }
Exemplo n.º 6
0
#pragma warning restore 0219, 414

    protected override void OnEnable()
    {
        base.OnEnable();

        this._sDiaryView = this.target as DiaryView;
    }
Exemplo n.º 7
0
        private async Task InitDiary()
        {
            Logger?.LogDebug("InitDiary");

            DiaryInfo = null;
            View      = null;

            if (!IsAuthenticated)
            {
                Logger?.LogDebug("Not Authenticated");
                return;
            }

            if (!string.IsNullOrWhiteSpace(DiaryName))
            {
                DiaryInfo = await GetDiaryInfo(DiaryName);

                MyDiaryInfo = await GetMyDiaryInfo();
            }
            else
            {
                DiaryInfo = MyDiaryInfo = await GetMyDiaryInfo();
            }

            if (DiaryInfo == null)
            {
                Logger?.LogDebug("DiaryInfo is null");
                return;
            }

            Logger?.LogDebug("Set DiaryInfo: {diaryInfo}", Json.Serialize(DiaryInfo));

            if (DiaryInfo.IsSecret && string.IsNullOrWhiteSpace(UserData.Password))
            {
                Navi.NavigateTo(DiaryUrl.SetPassword());
                return;
            }
            //WritableDiary = await DiaryService.GetWritableDiaryInfoAsync(User);
            //ViewableDiary = await DiaryService.GetViewableDiaryInfoAsync(User);

            if (HasDiaryInfo)
            {
                if (string.IsNullOrWhiteSpace(Date))
                {
                    View = await DiaryService.GetLastDiaryViewAsync(User, DiaryInfo);
                }
                else if (Date.TryToDate(out var parsedDate))
                {
                    View = await DiaryService.GetDiaryViewAsync(User, DiaryInfo, parsedDate);
                }

                if (DiaryInfo.IsSecret && HasDiaryContent)
                {
                    foreach (var content in View?.DiaryContents)
                    {
                        try
                        {
                            content.Text = content.Text.Decrypt(UserData.Password);
                        }
                        catch
                        {
                            content.Text = "임호화된 일기를 해석하지 못했습니다. 비밀번호를 다시 확인해주세요.";
                        }
                    }
                }
            }
        }