Esempio n. 1
0
        public IFeedback <long> AddMemo(Memo memo)
        {
            var feedback = new Feedback <long>();

            try
            {
                _entities.Tags.AddRange(memo.Tags);

                memo.CreatedAt = DateTime.UtcNow;
                memo.UpdatedAt = memo.CreatedAt;
                memo.Status    = _entities.Statuses.Where(s => s.Name == Statuses.Active.ToString()).FirstOrDefault();

                _entities.Memos.Add(memo);

                _entities.SaveChanges();
                feedback.Value  = memo.Id;
                feedback.Status = StatusEnum.Succeeded;
            }
            catch (Exception ex)
            {
                Log.Error($"Failed to add a new memo: {ex.Message}");
                feedback.Status = StatusEnum.Error;
            }
            return(feedback);
        }
Esempio n. 2
0
        public IFeedback <NoValue> CreateMemo(CreateMemoViewModel memo)
        {
            var feedback = new Feedback <NoValue>();

            try
            {
                Memo newMemo = new Memo()
                {
                    AspNetUserId = memo.userId,
                    CreatedAt    = DateTime.Now,
                    Note         = memo.Note,
                    StatusId     = (int)StatusEnum.Active,
                    Title        = memo.Title
                };

                _entities.Memo.Add(newMemo);

                List <string> tags    = memo.Tags.Split(' ').ToList();
                var           tagList = new List <Tag>();

                foreach (var tag in tags)
                {
                    if (!String.IsNullOrWhiteSpace(tag))
                    {
                        tagList.Add(new Tag()
                        {
                            Name = tag, Memo = newMemo
                        });
                    }
                }

                _entities.Tag.AddRange(tagList);
                _entities.SaveChanges();
                feedback.Status = StatusEnum.Success;
                Log.Information("New memo added - " + memo.Title);
            }
            catch (Exception ex)
            {
                feedback.Status  = StatusEnum.Error;
                feedback.Message = ex.GetBaseException().Message;
                Log.Debug(ex.GetBaseException().Message);
            }

            return(feedback);
        }