Exemplo n.º 1
0
 public static ContentModel ToModel(this Content entity)
 {
     var model = new ContentModel();
     AutoMapper.Mapper.CreateMap<Content, ContentModel>();
     AutoMapper.Mapper.Map(entity, model);
     return model;
 }
Exemplo n.º 2
0
        public ActionResult Contact()
        {
            var infoContact = new ContentModel();
            infoContact = HgtCache.Get<ContentModel>(CONTENT_CONTACT_INFO_KEY);
            if (infoContact == null)
            {
                var contact = _contactService.Find((int)ContentType.Contact);
                infoContact = contact.ToModel();
                HgtCache.Insert(CONTENT_CONTACT_INFO_KEY, infoContact);
            }

            var model = new ContactModel() { Departments = GetAllDepartments() };
            ViewData["ContactInfo"] = infoContact.Value;
            model.CaptchaShow = _captchaShow;
            if (!_captchaShow)
            {
                model.Captcha = "captcha";
            }

            return View(model);
        }
Exemplo n.º 3
0
        public string EditContent(ContentModel model)
        {
            if (ModelState.IsValid)
            {
                var entity = _contentService.Find(model.Id);
                if (entity != null)
                {
                    entity.LastUpdated = DateTime.Now;

                    if (entity.Name != model.Name)
                        entity.Name = model.Name;
                    if (entity.Value != model.Value)
                        entity.Value = model.Value;

                    _contentService.Update(entity);
                    _unitOfWork.SaveChanges();

                    return JsonConvert.SerializeObject(new { Status = ResultStatus.Success, Message = "Data were saved successfully!" });
                }
                return JsonConvert.SerializeObject(new { Status = ResultStatus.Fail, Message = "Data were saved unsuccessfully!" });
            }
            return JsonConvert.SerializeObject(new { Status = ResultStatus.Fail, Message = "Data were saved unsuccessfully!" });
        }
Exemplo n.º 4
0
        public ActionResult Index(int? id)
        {
            if (id == 0 || id == null)
                id = 1;
            var model = new ContentModel();
            var entity = _contentService.Find(id);
            if (entity != null)
                model = entity.ToModel();

            ViewData["CategoryId"] = id.ToString();
            ViewData["ListContents"] = GetListContents();
            return View(model);
        }