Exemple #1
0
        public bool SaveAuthor(IncomeAuthorModel model, bool isIncome = false)
        {
            try
            {
                if (model.ImageTempId != null)
                {
                    model.Photo = GetFileContent(model.ImageTempId);
                }
                var xmlString = SerializeModel(model);
                if (User.IsInRole("ADMIN") && isIncome && model.Id != null)
                {
                    DataService.UpdateIncomeItem((Guid)model.Id, model.Name, xmlString);
                }
                else
                {
                    var id = DataService.ApplyIncomeItem(ItemTypeEnum.Author, (Guid)User.UserId, model.Name, xmlString, model.Id);
                    _mailService.NewIncome(id);
                }

                return(true);
            }
            catch (Exception ex)
            {
                // todo
            }
            return(false);
        }
Exemple #2
0
        public JsonResult LoadAuthor(Guid authorId)
        {
            IncomeAuthorModel model;
            Guid?userId = null;

            if (!User.IsInRole("ADMIN"))
            {
                userId = User.UserId;
            }
            var authorXml = DataService.GetIncomeItem(ItemTypeEnum.Author, authorId, userId);

            if (!string.IsNullOrEmpty(authorXml))
            {
                model = DeserializeModel <IncomeAuthorModel>(authorXml);
                if (model.Photo != null)
                {
                    model.ImageTempId = Guid.NewGuid();
                    Session[model.ImageTempId.ToString()] = model.Photo;
                    model.Photo = null;
                }
            }
            else
            {
                var author = DataService.GetAuthor(authorId, null);
                model = new IncomeAuthorModel
                {
                    Biography = author.Description,
                    BirthDate = author.BornDate,
                    DeathDate = author.DeathDate,
                    Id        = author.Id,
                    Name      = author.Name,
                    HasImage  = author.HasImage
                };
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }