示例#1
0
        public virtual async Task <D> Update(Guid id, D model, Guid?userId = null, bool isCommit = true)
        {
            try
            {
                Guid _userId = userId == null ? Guid.Empty : userId.Value;

                D oldRec = await Repository.GetByID(id);

                if (Validation.IsNull(oldRec))
                {
                    return(null);
                }

                ModelCopier.CopyModel(model, oldRec);

                if (oldRec is ITableEntity)
                {
                    (oldRec as ITableEntity).UpdateBy       = _userId;
                    (oldRec as ITableEntity).UpdateDateTime = DateTime.Now;
                }

                Repository.Update(oldRec);

                if (isCommit)
                {
                    await Commit();
                }

                return(oldRec);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#2
0
        public ActionResult Save(SubmitModel model)
        {
            SessionHelper.Temp  = model.DistrictId;
            SessionHelper.Temp2 = model.UpazillaId;
            SessionHelper.Temp3 = model.CollectedBy;

            HnppData entity = new HnppData();


            ModelCopier.CopyModel(model, entity);

            entity.InsertedById = SessionHelper.UserId;

            if (entity.Id == 0)
            {
                sunDataService.Add(entity);
            }
            else
            {
                sunDataService.Update(entity);
            }

            unitOfWork.Commit();

            return(PartialView());
        }
示例#3
0
        public void Update(RoleDb model, List <RoleModuleRelationDb> roleModuleRelations)
        {
            using (var db = PermissionDal.DbContext)
            {
                using (var dbContextTransaction = PermissionDal.DbContext.Database.BeginTransaction()) //起一个事务
                {
                    try
                    {
                        RoleDb tempModel = PermissionDal.GetModel(c => c.role_id == model.role_id);

                        ModelCopier.CopyModel(model, tempModel, "creator_name",
                                              "creator_full_name", "creator_time");
                        PermissionDal.EditData(tempModel);
                        PermissionDal.DbContext.Database.ExecuteSqlCommand(" delete from role_module_relation where role_id=@p0 ", model.role_id);
                        PermissionDal.AddList(roleModuleRelations);
                        PermissionDal.DbContext.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                    finally
                    {
                        PermissionDal.DbContextDispose();
                    }
                }
            }
        }
示例#4
0
        public CalendarEventStub Create(CalendarEventStub calendarEvent)
        {
            var createRequest = new CalendarEventCreateRequest();

            ModelCopier.CopyModel(calendarEvent, createRequest);
            return(Api.Calendars.CreateEventForCalendar(this.Id, createRequest));
        }
示例#5
0
        public ActionResult Save(RoleModel model)
        {
            try
            {
                Role entity = new Role();

                ModelCopier.CopyModel(model, entity);


                if (model.Id == 0)
                {
                    roleService.Add(entity);
                }
                else
                {
                    roleService.Update(entity);
                }

                unitOfWork.Commit();

                return(PartialView());
            }
            catch
            {
                return(RedirectToAction("Error", "Main"));
            }
        }
示例#6
0
        public ActionResult Save(UserProfileModel model)
        {
            var login = service.GetByPin(model.Pin);

            if (login != null)
            {
                model.Roles = roleService.GetAll().ToSelectList(null, "Id", "RoleName");

                ModelState.AddModelError("", "User has exists");
                return(PartialView("Create", model));
            }

            model.Password = "" + model.Password.ToMD5();

            UserProfile entity = new UserProfile();

            ModelCopier.CopyModel(model, entity);

            service.Add(entity);

            unitOfWork.Commit();
            SessionHelper.Temp = null;

            return(PartialView());
        }
示例#7
0
        public ActionResult SaveMulti(SubmitModel model)
        {
            SessionHelper.Temp  = model.DistrictId;
            SessionHelper.Temp2 = model.UpazillaId;

            foreach (var v in model.MultiDatas)
            {
                if (v.Count > 0)
                {
                    SummerizedData entity = new SummerizedData();

                    ModelCopier.CopyModel(model, entity);

                    entity.InsertedById = SessionHelper.UserId;
                    entity.SourceId     = v.Id;
                    entity.ReachCount   = v.Count;
                    entity.CollectedBy  = v.CollectedBy;

                    if (entity.Id > 0)
                    {
                        sunDataService.Update(entity);
                    }
                    else
                    {
                        sunDataService.Add(entity);
                    }
                }
            }

            unitOfWork.Commit();

            return(PartialView("Save"));
        }
示例#8
0
        public static CompanyRegisterRecordViewModel Dto(this CompanyRegisterRecord o)
        {
            var viewMode = new CompanyRegisterRecordViewModel();

            ModelCopier.CopyModel(o, viewMode);
            viewMode.CreatedTime = o.CreatedTime.ToString("yyyy-MM-dd");
            return(viewMode);
        }
示例#9
0
        public static CompanyRegisterChangeRecordViewModel Dto(this CompanyRegistersChangeRecord o)
        {
            var viewMode = new CompanyRegisterChangeRecordViewModel();

            ModelCopier.CopyModel(o, viewMode);
            //viewMode.EditTime = o.EditTime.ToString("yyyy-MM-dd");
            return(viewMode);
        }
示例#10
0
        public ActionResult Details(int id)
        {
            UserProfile      entity = service.GetDataById(id);
            UserProfileModel model  = new UserProfileModel();

            ModelCopier.CopyModel(entity, model);
            return(PartialView(model));
        }
示例#11
0
        public ActionResult Edit(int Id)
        {
            var entity = standingDataService.GetDataById(Id);

            StandingDataModel model = new StandingDataModel();

            ModelCopier.CopyModel(entity, model);

            return(PartialView("Create", model));
        }
示例#12
0
        public ActionResult Edit(int Id)
        {
            var entity = service.GetDataById(Id);

            ViewBag.RoleId = new SelectList(roleService.GetAll(), "Id", "RoleName", entity.RoleId);

            UserProfileModel model = new UserProfileModel();

            ModelCopier.CopyModel(entity, model);

            return(PartialView("Create", model));
        }
示例#13
0
 public ActionResult Add(AdminUserWebM model)
 {
     if (ModelState.IsValid && model != null)
     {
         AdminUserDb adminUserDb = new AdminUserDb();
         model.user_name = model.user_name.Trim();
         ModelCopier.CopyModel(model, adminUserDb);
         AdminUserBll.Instance.Add(adminUserDb, model.role_ids);
         return(Content("<script>alert('添加用户成功!');parent.layer.closeAll('iframe');</script>"));
     }
     return(View(model));
 }
示例#14
0
        public void CopyModel_FromIsNull_DoesNothing()
        {
            // Arrange
            GenericModel <int> from = null;
            GenericModel <int> to   = new GenericModel <int> {
                TheProperty = 42
            };

            // Act
            ModelCopier.CopyModel(from, to);

            // Assert
            Assert.Equal(42, to.TheProperty);
        }
示例#15
0
        public ActionResult Edit(EditUserModel model)
        {
            try {
                User user = _repository.GetUser(model.UserName);
                ModelCopier.CopyModel(model, user);
                _repository.Update(user);

                return(RedirectToAction("Details", new { id = model.UserName }));
            } catch (Exception) {
                ModelState.AddModelError("", "Edit Failure, see inner exception.");
            }

            return(View(model));
        }
示例#16
0
        public void CopyModel_ToIsNull_DoesNothing()
        {
            // Arrange
            GenericModel <int> from = new GenericModel <int> {
                TheProperty = 21
            };
            GenericModel <int> to = null;

            // Act
            ModelCopier.CopyModel(from, to);

            // Assert
            Assert.Equal(21, from.TheProperty);
        }
示例#17
0
        public void CopyCollection_ToIsNull_DoesNothing()
        {
            // Arrange
            List <int> from = new List <int> {
                1, 2, 3
            };
            List <int> to = null;

            // Act
            ModelCopier.CopyCollection(from, to);

            // Assert
            Assert.Equal(new[] { 1, 2, 3 }, from.ToArray());
        }
示例#18
0
        public void CopyCollection_ToIsNull_DoesNothing()
        {
            // Arrange
            List <int> from = new List <int>()
            {
                1, 2, 3
            };
            List <int> to = null;

            // Act
            ModelCopier.CopyCollection(from, to);

            // Assert
            CollectionAssert.AreEqual(new int[] { 1, 2, 3 }, from);
        }
示例#19
0
        public ActionResult Edit(string id)
        {
            User user = _repository.GetUser(id);

            if (user == null)
            {
                return(RedirectToAction("Index"));
            }

            EditUserModel model = new EditUserModel();

            ModelCopier.CopyModel(user, model);

            return(View(model));
        }
示例#20
0
        public void CopyCollection_ToIsImmutable_DoesNothing()
        {
            // Arrange
            List <int> from = new List <int> {
                1, 2, 3
            };
            ICollection <int> to = new ReadOnlyCollection <int>(new[] { 4, 5, 6 });

            // Act
            ModelCopier.CopyCollection(from, to);

            // Assert
            Assert.Equal(new[] { 1, 2, 3 }, from.ToArray());
            Assert.Equal(new[] { 4, 5, 6 }, to.ToArray());
        }
示例#21
0
        public void CopyModel_ToIsReadOnly_DoesNothing()
        {
            // Arrange
            GenericModel <int> from = new GenericModel <int> {
                TheProperty = 21
            };
            ReadOnlyGenericModel <int> to = new ReadOnlyGenericModel <int>(42);

            // Act
            ModelCopier.CopyModel(from, to);

            // Assert
            Assert.Equal(21, from.TheProperty);
            Assert.Equal(42, to.TheProperty);
        }
示例#22
0
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Detail(string key = "")
        {
            DictionaryWebM webModel = new DictionaryWebM();

            if (string.IsNullOrEmpty(key))
            {
                ViewBag.EditType = false;
            }
            else
            {
                ViewBag.EditType = true;
                DictionaryTableDb model = DictionaryTableBll.Instance.GetModel(key);
                ModelCopier.CopyModel(model, webModel);
            }
            return(View(webModel));
        }
示例#23
0
        public void CopyModel_LiftedTypeMatch_ActualValueIsNotNull_Copies()
        {
            // Arrange
            GenericModel <int?> from = new GenericModel <int?> {
                TheProperty = 21
            };
            GenericModel <int> to = new GenericModel <int> {
                TheProperty = 42
            };

            // Act
            ModelCopier.CopyModel(from, to);

            // Assert
            Assert.Equal(21, from.TheProperty);
            Assert.Equal(21, to.TheProperty);
        }
示例#24
0
        public void CopyModel_ExactTypeMatch_Copies()
        {
            // Arrange
            GenericModel <int> from = new GenericModel <int> {
                TheProperty = 21
            };
            GenericModel <int> to = new GenericModel <int> {
                TheProperty = 42
            };

            // Act
            ModelCopier.CopyModel(from, to);

            // Assert
            Assert.Equal(21, from.TheProperty);
            Assert.Equal(21, to.TheProperty);
        }
示例#25
0
        public void CopyCollection_ToIsMmutable_ClearsAndCopies()
        {
            // Arrange
            List <int> from = new List <int> {
                1, 2, 3
            };
            ICollection <int> to = new List <int> {
                4, 5, 6
            };

            // Act
            ModelCopier.CopyCollection(from, to);

            // Assert
            Assert.Equal(new[] { 1, 2, 3 }, from.ToArray());
            Assert.Equal(new[] { 1, 2, 3 }, to.ToArray());
        }
示例#26
0
        public void CopyModel_NoTypeMatch_DoesNothing()
        {
            // Arrange
            GenericModel <int> from = new GenericModel <int> {
                TheProperty = 21
            };
            GenericModel <long> to = new GenericModel <long> {
                TheProperty = 42
            };

            // Act
            ModelCopier.CopyModel(from, to);

            // Assert
            Assert.Equal(21, from.TheProperty);
            Assert.Equal(42, to.TheProperty);
        }
示例#27
0
        public ActionResult Edit(int Id)
        {
            try
            {
                var entity = roleService.GetDataById(Id);

                RoleModel model = new RoleModel();
                model.RoleDefaultPages = defaultService.GetRoleDefaultPageList().ToSelectList(null, "Id", "Name");
                ModelCopier.CopyModel(entity, model);

                return(PartialView("Create", model));
            }
            catch
            {
                return(RedirectToAction("Error", "Main"));
            }
        }
示例#28
0
        public void CopyModel_LiftedTypeMatch_ActualValueIsNull_DoesNothing()
        {
            // Arrange
            GenericModel <int?> from = new GenericModel <int?> {
                TheProperty = null
            };
            GenericModel <int> to = new GenericModel <int> {
                TheProperty = 42
            };

            // Act
            ModelCopier.CopyModel(from, to);

            // Assert
            Assert.Null(from.TheProperty);
            Assert.Equal(42, to.TheProperty);
        }
示例#29
0
        public void CopyModel_ToDoesNotContainProperty_DoesNothing()
        {
            // Arrange
            GenericModel <int> from = new GenericModel <int> {
                TheProperty = 21
            };
            OtherGenericModel <int> to = new OtherGenericModel <int> {
                SomeOtherProperty = 42
            };

            // Act
            ModelCopier.CopyModel(from, to);

            // Assert
            Assert.Equal(21, from.TheProperty);
            Assert.Equal(42, to.SomeOtherProperty);
        }
示例#30
0
        public ActionResult Create(CreateUserModel model)
        {
            try {
                if (ModelState.IsValid)
                {
                    User user = new User();
                    ModelCopier.CopyModel(model, user);
                    _repository.CreateNewUser(user);

                    return(RedirectToAction("Details", new { id = user.UserName }));
                }
            } catch (Exception) {
                ModelState.AddModelError("", "Create Failure, try another user name or" +
                                         " see inner exception.");
            }

            return(View("Create", model));
        }