示例#1
0
        public ActionResult Input(BannerModel model)
        {
            if (ModelState.IsValid)
            {
                Banner entity = null;
                try
                {
                    if (model.Id > 0)
                        entity = _bannerService.Find(model.Id);
                    else
                        entity = new Banner();

                    #region Set value for category entity

                    entity.Title = model.Title;
                    entity.Description = model.Description;
                    entity.Link = model.Link;
                    entity.OpenLink = model.OpenLink;
                    entity.FileName = model.FileName != null ? model.FileName : "default.jpg";
                    entity.IsActive = model.IsActive;
                    entity.DisplayOrder = model.DisplayOrder;

                    #endregion

                    #region Perform save data
                    if (model.Id <= 0)
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            _bannerService.Insert(entity);
                            _unitOfWork.SaveChanges();
                            scope.Complete();
                        }
                    }
                    else
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            _bannerService.Update(entity);
                            _unitOfWork.SaveChanges();
                            scope.Complete();
                        }
                    }

                    return Json(new { Status = ResultStatus.Success, Message = StringTable.DataSaveSuccess });
                    #endregion
                }
                catch
                {
                    return Json(new { Status = ResultStatus.Fail, Message = StringTable.DataSaveUnsuccess });
                }
            }
            else
            {
                return Json(new { Status = ResultStatus.Fail, Message = StringTable.DataSaveUnsuccess });
            }
        }
示例#2
0
 public static BannerModel ToModel(this Banner entity)
 {
     var model = new BannerModel();
     AutoMapper.Mapper.CreateMap<Banner, BannerModel>();
     AutoMapper.Mapper.Map(entity, model);
     return model;
 }