public ActionResult Update(BlogViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Blog blog = new Blog();
             PropertyCopy.Copy(model, blog);
             blogRepository.Update(blog);
             blogRepository.Save(requestContext);
             return(RedirectToAction("Index"));
         }
         catch (Exception)
         {
             ViewBag.slugs = blogCategoryRepository.All.Select(b => new SelectListItem
             {
                 Text  = b.Slug,
                 Value = b.Slug
             }).ToList();
             return(View());
         }
     }
     ViewBag.slugs = blogCategoryRepository.All.Select(b => new SelectListItem
     {
         Text  = b.Slug,
         Value = b.Slug
     }).ToList();
     return(View());
 }
        public IActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.Id       = Guid.NewGuid().ToString();
                    model.UserName = model.FullName;
                    User user = new User();
                    PropertyCopy.Copy(model, user);
                    user.Password = Security.EncryptPassword(model.Password);
                    Customer customer = new Customer()
                    {
                        Id    = model.Id,
                        Email = model.Email
                    };

                    accountRepository.Add(customer);
                    userRepository.Add(user);
                    userRepository.Save();
                    accountRepository.Save();
                    return(RedirectToAction("Index"));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(View());
        }
示例#3
0
        public void Save(ServiceRegisterViewModel model, Guid idAccount)
        {
            var service = ConvertService.FromServiceRegisterViewModel(model);

            service.IdAccount = idAccount;

            //Cuando es un nuevo servicio
            if (service.Id == Guid.Empty)
            {
                _serviceDao.InsertOrUpdate(service);
                _redisCache.flush(service.Id.ToString());
            }
            //Cuando es un servicio existente
            else
            {
                var exService = _serviceDao.GetOne(service.Id, idAccount);

                PropertyCopy.Copy(service, exService);

                service = null;

                //_serviceDao.Context.SaveChanges();
                //_serviceDao.InsertOrUpdate(exService);
                UpdateEntireService(exService, idAccount);
                foreach (var item in _serviceDao.Getcampaign(exService.Id))
                {
                    _redisCache.flush("CampaignServices:" + item.IdCampaign.ToString());
                }
            }

            //UpdateEntireService(service, idAccount);
        }
示例#4
0
 public ActionResult Create(BlogCategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (!blogCategoryRepository.CheckNewSlug(model.Slug))
             {
                 model.Id = Guid.NewGuid().ToString();
                 BlogCategory blogCategory = new BlogCategory();
                 PropertyCopy.Copy(model, blogCategory);
                 blogCategory.HierarchyCode = blogCategoryRepository.GenerateHierarchyCode(model.ParentHierarchyCode);
                 blogCategoryRepository.Add(blogCategory);
                 blogCategoryRepository.Save(RequestContext);
                 return(RedirectToAction("Index"));
             }
             else
             {
                 SetComboData();
                 return(View());
             }
         }
         catch (Exception)
         {
             SetComboData();
             return(View());
         }
     }
     SetComboData();
     return(View());
 }
示例#5
0
        public void SetConfiguration()
        {
            var siteSetting = _siteSettingRepository.Single();
            var mailSetting = _mailSettingRepository.Single();
            var ssoSetting  = _ssoSettingRepository.Single();

            var configuration = new ConfigurationViewModel()
            {
                MailSetting = new MailSettingViewModel(),
                SSOSetting  = new SSOSettingViewModel(),
                SiteSetting = new SiteSettingViewModel()
            };

            if (siteSetting != null)
            {
                PropertyCopy.Copy(siteSetting, configuration.SiteSetting);
            }
            if (mailSetting != null)
            {
                PropertyCopy.Copy(mailSetting, configuration.MailSetting);
            }
            if (ssoSetting != null)
            {
                PropertyCopy.Copy(ssoSetting, configuration.SSOSetting);
            }
            SetConfiguration(configuration);
        }
 public ActionResult Update(CategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (!categoryRepository.CheckSlugExist(model.Slug))
             {
                 Category category = categoryRepository.Single(p => p.Id == model.Id);
                 PropertyCopy.Copy(model, category);
                 string CurrentHierarchyParent = category.HierarchyCode.Substring(0, category.HierarchyCode.Length - Domain.Common.Consts.Infrastructure.HierarchyCodeLength);
                 if (string.IsNullOrEmpty(model.ParentHierarchyCode) ? !string.IsNullOrEmpty(CurrentHierarchyParent) : model.ParentHierarchyCode != CurrentHierarchyParent)
                 {
                     var HierarchyCode = categoryRepository.GenerateHierarchyCode(model.ParentHierarchyCode);
                     var ChildMenus    = categoryRepository.GetChildMenus(category.HierarchyCode);
                     foreach (Category item in ChildMenus)
                     {
                         item.HierarchyCode = model.ParentHierarchyCode + item.HierarchyCode.Substring(HierarchyCode.Length);
                     }
                     category.HierarchyCode = HierarchyCode;
                 }
                 categoryRepository.Update(category);
                 categoryRepository.Save(requestContext);
             }
         }
         catch (Exception)
         {
             SetComboData(model.HierarchyCode);
             return(View());
         }
         return(RedirectToAction("Index"));
     }
     SetComboData(model.HierarchyCode);
     return(View());
 }
示例#7
0
        public void Save(ServiceRegisterViewModel model, Guid idAccount)
        {
            var service = ConvertService.FromServiceRegisterViewModel(model);

            service.IdAccount = idAccount;

            //Cuando es un nuevo servicio
            if (service.Id == Guid.Empty)
            {
                _serviceDao.InsertOrUpdate(service);
            }
            //Cuando es un servicio existente
            else
            {
                var exService = _serviceDao.GetOne(service.Id, idAccount);

                PropertyCopy.Copy(service, exService);

                service = null;

                //_serviceDao.Context.SaveChanges();
                //_serviceDao.InsertOrUpdate(exService);
                UpdateEntireService(exService, idAccount);
            }

            //UpdateEntireService(service, idAccount);
        }
示例#8
0
        public SkillSettings Clone()
        {
            var newObj = new SkillSettings();

            PropertyCopy.Copy(this, newObj);
            return(newObj);
        }
示例#9
0
        private void InitializeDocumentForUpsert(string action)
        {
            // Initialize dropdowns
            Drivers          = driversService.GetDrivers();
            Policemen        = nomenclatureService.GetPolicemen();
            Violations       = nomenclatureService.GetViolations();
            ChosenViolations = new ObservableCollection <Violation>();

            if (action != "Insert")
            {
                PropertyCopy.Copy(SelectedDocument, UpsertedDocument);
            }
            else
            {
                UpsertedDocument = new Document();
            }

            // Init violations
            if (UpsertedDocument.Violations != null)
            {
                UpsertedDocument.Violations.ForEach(v => ChosenViolations.Add(v));
            }

            // Init date
            if (UpsertedDocument.Date == new DateTime())
            {
                UpsertedDocument.Date = DateTime.Now;
            }
        }
 public ActionResult Create(CategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (!categoryRepository.CheckSlugExist(model.Slug))
             {
                 model.Id = Guid.NewGuid().ToString();
                 Category category = new Category();
                 PropertyCopy.Copy(model, category);
                 category.HierarchyCode = categoryRepository.GenerateHierarchyCode(model.ParentHierarchyCode);
                 categoryRepository.Add(category);
                 categoryRepository.Save(requestContext);
                 return(RedirectToAction("Index"));
             }
         }
         catch (Exception)
         {
             SetComboData();
             return(View());
         }
     }
     SetComboData();
     return(View());
 }
示例#11
0
        public async Task AddMovieReview(ReviewRequestModel reviewRequest)
        {
            var rev = new Review();

            PropertyCopy.Copy(rev, reviewRequest);
            var res = await _reviewRepo.AddAsync(rev);
        }
示例#12
0
        private void UpdateDocument(object obj)
        {
            if (UpsertedDocument != new Document())
            {
                UpsertedDocument.Violations = ChosenViolations.ToList();
                if (documentsService.UpdateDocument(UpsertedDocument))
                {
                    var existingRecord = Documents.FirstOrDefault(d => d.Id == UpsertedDocument.Id);
                    PropertyCopy.Copy(UpsertedDocument, existingRecord);
                    //Documents.Remove(existingRecord);
                    //Documents.Add(UpsertedDocument);

                    Messenger.ShowMessage("Успешна редакция", MessageType.Success);
                }
                else
                {
                    Messenger.ShowMessage("Грешка при редакция на документа!", MessageType.Error);
                }

                ResetDocumentOnUpsert();
            }
            else
            {
                Messenger.ShowMessage("Грешка при редакция на документа!", MessageType.Error);
            }
        }
 public static IEnumerable <ExtendedPlayHistory> ConvertToExtendedPlayHistory(CursorPaging <PlayHistory> history)
 {
     foreach (var page in history.Items)
     {
         yield return(PropertyCopy <ExtendedPlayHistory> .CopyFrom(page));
     }
 }
示例#14
0
        //[Authorize(Roles = "ViewUserGroup")]
        public IEnumerable <ApplicationRoleViewModel> Details(int id)
        {
            ApplicationGroup appGroup = _appGroupService.GetDetail(id);

            if (appGroup == null)
            {
                return(null);
            }
            //  var appGroupViewModel = ViewModelMapper<ApplicationGroupViewModel, ApplicationGroup>(appGroup);
            var appGroupViewModel = PropertyCopy.Copy <ApplicationGroupViewModel, ApplicationGroup> (appGroup);



            var listRoleByGroup          = _appRoleService.GetListRoleByGroupId(appGroupViewModel.ID).ToList();
            var listRoleByGroupViewModel = ViewModelMapper <ApplicationRoleViewModel, IdentityRole> .MapObjects(listRoleByGroup, null);

            var listRole          = _appRoleService.GetAll().ToList();
            var listRoleViewModel = ViewModelMapper <ApplicationRoleViewModel, IdentityRole> .MapObjects(listRole, null);

            foreach (var roleViewModel in listRoleViewModel)
            {
                foreach (var roleByGroupViewModel in listRoleByGroupViewModel)
                {
                    if (roleByGroupViewModel.Id.Equals(roleViewModel.Id))
                    {
                        roleViewModel.Check = true;
                        break;
                    }
                }
            }

            return(listRoleViewModel);
        }
        public JsonResult Action(CityActionModel model)
        {
            bool result;

            if (model.ID > 0)
            {
                City objectFirst = service.GetByID(model.ID);
                PropertyCopy.Copy(model, objectFirst);
                result = service.Update(objectFirst);
            }
            else
            {
                City objectFirst = new City
                {
                    Name       = model.Name,
                    ProvinceID = model.ProvinceID
                };
                result = service.Save(objectFirst);
            }

            JsonResult jsonResult = new JsonResult
            {
                Data = result ? (new { Success = true, Msg = "" }) : (new { Success = false, Msg = "Unable to Save Course" })
            };

            return(jsonResult);
        }
示例#16
0
 public virtual void Modificar(T entityActual, T entityModificada, string[] camposModificados, bool noMoficarFechaEdicion = false, bool esWs = false)
 {
     try
     {
         if (!noMoficarFechaEdicion)
         {
             var index = camposModificados.Length;
             Array.Resize(ref camposModificados, index + 1);
             camposModificados[index]      = "FechaEdicion";
             entityModificada.FechaEdicion = DateTime.Now;
         }
         //PropertyCopy para obligar a cargar la entidad actual y evitar un  error
         //  PropertyCopy.Copy(entityActual, entityActual);
         entityActual.ReinicializarLista(camposModificados);
         _repositorio.Modificar(entityActual);
         PropertyCopy.Copy(entityModificada, entityActual, camposModificados);
         _unitOfWork.SaveChanges();
     }
     catch (DbEntityValidationException e)
     {
         throw e;
     }
     catch (Exception ex)
     {
         // throw _exceptionMgr.HandleException("Ocurrió un error al editar el ítem", ex);
     }
 }
示例#17
0
        public ShopAddressViewModel GetShopAddressViewModelById(string id)
        {
            var model = this.All.Where(m => m.Id == id).FirstOrDefault();
            ShopAddressViewModel viewModel = new ShopAddressViewModel();

            PropertyCopy.Copy(model, viewModel);
            return(viewModel);
        }
        public ActionResult Delete(int ID)
        {
            Province            objectFirst = service.GetByID(ID);
            ProvinceActionModel model       = new ProvinceActionModel();

            PropertyCopy.Copy(objectFirst, model);
            return(PartialView("_Delete", model));
        }
示例#19
0
        public void MultipleProperties()
        {
            ThreeProperties target = PropertyCopy <ThreeProperties> .CopyFrom(new { Third = true, Second = 20, First = "multiple" });

            Assert.AreEqual("multiple", target.First);
            Assert.AreEqual(20, target.Second);
            Assert.IsTrue(target.Third);
        }
示例#20
0
        public ActionResult Delete(int ID)
        {
            CourseCategory            objectFirst = service.GetByID(ID);
            CourseCategoryActionModel model       = new CourseCategoryActionModel();

            PropertyCopy.Copy(objectFirst, model);
            return(PartialView("_Delete", model));
        }
        public MaterialViewModel GetMaterialViewModelById(string id)
        {
            var model = this.All.Where(m => m.Id == id).FirstOrDefault();
            MaterialViewModel viewModel = new MaterialViewModel();

            PropertyCopy.Copy(model, viewModel);
            return(viewModel);
        }
示例#22
0
        public void CopyToSimilarType()
        {
            Simple source = new Simple {
                Value = "test"
            };
            OtherSimple target = PropertyCopy <OtherSimple> .CopyFrom(source);

            Assert.AreEqual("test", target.Value);
        }
示例#23
0
        public void CopyFromGenericType()
        {
            Generic <string> source = new Generic <string> {
                Value = "value"
            };
            Simple target = PropertyCopy <Simple> .CopyFrom(source);

            Assert.AreEqual("value", target.Value);
        }
示例#24
0
        public void CopyToGenericType()
        {
            Simple source = new Simple {
                Value = "value"
            };
            Generic <string> target = PropertyCopy <Generic <string> > .CopyFrom(source);

            Assert.AreEqual("value", target.Value);
        }
示例#25
0
        public void WriteOnlyTargetPropertyIsIgnored()
        {
            WriteOnly source = new WriteOnly {
                Value = "copied", Write = "ignored"
            };
            Simple target = PropertyCopy <Simple> .CopyFrom(source);

            Assert.AreEqual("copied", target.Value);
        }
示例#26
0
        public async Task <UserRegisterResponseModel> GetUserDetails(int id)
        {
            var user = await _userRepository.GetByIdAsync(id);

            var details = new UserRegisterResponseModel();

            PropertyCopy.Copy(details, user);
            return(details);
        }
示例#27
0
        public void DerivedTypeIsAccepted()
        {
            Generic <Derived> source = new Generic <Derived> {
                Value = new Derived()
            };
            Generic <Base> target = PropertyCopy <Generic <Base> > .CopyFrom(source);

            Assert.AreSame(source.Value, target.Value);
        }
示例#28
0
    static void Main()
    {
        A a = new A();

        a.Foo = 17;
        B b = PropertyCopy <B> .CopyFrom(a);

        bool success = b.Foo == 17;     // success is true;
    }
示例#29
0
        public async Task <JsonResult> Cadastrar(Usuario usuario, bool novo, String senhaAtual, String novaSenha)
        {
            IdentityResult result = null;

            if (ModelState.IsValid)
            {
                try
                {
                    if (novo)
                    {
                        var user = new ApplicationUser()
                        {
                            UserName = usuario.Email, Email = usuario.Email
                        };
                        user.DadosUsuario = usuario;
                        IdentityUserRole role = new IdentityUserRole();
                        role.RoleId = "1";
                        role.UserId = user.Id;
                        user.Roles.Add(role);
                        result = await UserManager.CreateAsync(user, novaSenha);

                        if (result.Succeeded)
                        {
                            await SignInAsync(user, isPersistent : false);

                            //return result.Errors;
                        }
                        else
                        {
                            AddErrors(result);
                        }
                    }
                    else
                    {
                        var  user     = UserManager.FindByEmail(usuario.Email);
                        bool atualiza = true;
                        if (senhaAtual != novaSenha)
                        {
                            result   = UserManager.ChangePassword(user.Id, senhaAtual, novaSenha);
                            atualiza = result.Succeeded;
                        }
                        if (atualiza)
                        {
                            PropertyCopy.Copy(usuario, user.DadosUsuario);
                            result = UserManager.Update(user);
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = new IdentityResult(new [] { ex.Message });
                }
            }
            // If we got this far, something failed, redisplay form
            return(Json(result, "application/json", JsonRequestBehavior.AllowGet));
        }
示例#30
0
        public ActionResult Assumir(ItemInbox item)
        {
            try
            {
                List <Incidente> lista = IncidenteBusiness.Consulta.Where(a =>
                                                                          string.IsNullOrEmpty(a.UsuarioExclusao) && a.UniqueKey.Equals(item.UniqueKey)).ToList();

                if (lista == null || lista.Count == 0)
                {
                    throw new Exception("Não foi possível recuperar o incidente através da identificação recebida.");
                }
                else
                {
                    ReiniciarCache(CustomAuthorizationProvider.UsuarioAutenticado.Login);

                    bool first = true;
                    foreach (Incidente obj in lista)
                    {
                        obj.StatusWF        = "SO";
                        obj.DataExclusao    = DateTime.Now;
                        obj.UsuarioExclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                        IncidenteBusiness.Alterar(obj);

                        if (first)
                        {
                            first = false;
                            Incidente obj2 = new Incidente();
                            PropertyCopy.Copy(obj, obj2);

                            obj2.ID       = Guid.NewGuid().ToString();
                            obj2.StatusWF = "RS";

                            if (!string.IsNullOrEmpty(item.Comentarios))
                            {
                                obj2.MensagemPasso = item.Comentarios;
                            }

                            obj2.Responsavel     = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                            obj2.UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                            obj2.UsuarioExclusao = null;
                            obj2.DataExclusao    = DateTime.MaxValue;

                            IncidenteBusiness.Inserir(obj2);

                            Severino.GravaCookie("MensagemSucesso", "O incidente " + obj2.Codigo + " foi redirecionado para a sua caixa pessoal.", 10);
                        }
                    }
                }

                return(Json(new { sucesso = "O passo do workflow associado ao documento foi aprovado com sucesso." }));
            }
            catch (Exception ex)
            {
                return(Json(new { erro = ex.Message }));
            }
        }
示例#31
0
        public override IEnumerable<IVertex> UpdateVertices(RequestUpdate myUpdate,
                                                            Int64 myTransaction,
                                                            SecurityToken mySecurity)
        {
            var toBeUpdated = GetVertices(myUpdate.GetVerticesRequest, myTransaction, mySecurity);

            var groupedByTypeID = toBeUpdated.GroupBy(_ => _.VertexTypeID);

            if (groupedByTypeID.CountIsGreater(0))
            {
                Dictionary<IVertex, Tuple<long?, String, VertexUpdateDefinition>> updates =
                    new Dictionary<IVertex, Tuple<long?, String, VertexUpdateDefinition>>();

                foreach (var group in groupedByTypeID)
                {
                    var vertexType = _vertexTypeManager
                                        .ExecuteManager
                                        .GetType(group.Key, myTransaction, mySecurity);

                    //we copy each property in property provider, 
                    //because an unknown property can be a structured at one type but unstructured at the other.
                    //this must be refactored:
                    //idea cancel IPropertyProvider. Change ConvertUnknownProperties to fill the dictionaries directly.
                    PropertyCopy copy = new PropertyCopy(myUpdate);
                    ConvertUnknownProperties(copy, vertexType);

                    if (copy.StructuredProperties != null)
                    {
                        var toBeUpdatedStructuredNames = copy.StructuredProperties.Select(_ => _.Key).ToArray();

                        foreach (var uniqueIndex in vertexType.GetUniqueDefinitions(false))
                        {
                            //if the unique index is defined on a property that will be updated
                            if (uniqueIndex.UniquePropertyDefinitions.Any(_ => toBeUpdatedStructuredNames.Contains(_.Name)))
                            {
                                //the list of property names, that can make an update of multiple vertices on unique properties unique again.

                                var uniquemaker = uniqueIndex.UniquePropertyDefinitions.Select(_ => _.Name).Except(toBeUpdatedStructuredNames);
                                if (!uniquemaker.CountIsGreater(0) && group.CountIsGreater(0))
                                    throw new IndexUniqueConstrainViolationException(vertexType.Name, String.Join(", ", uniquemaker));
                            }
                        }

                        var toBeUpdatedUniques = vertexType
                                                    .GetUniqueDefinitions(true)
                                                    .Where(_ => _.UniquePropertyDefinitions.Any(__ => toBeUpdatedStructuredNames.Contains(__.Name)));
                    }

                    foreach (var vertex in group)
                    {

                        //var toBeUpdatedIndices = (copy.StructuredProperties != null)
                        //                            ? copy.StructuredProperties.ToDictionary(_ => _.Key, _ => vertexType.GetPropertyDefinition(_.Key).InIndices)
                        //                            : null;

                        var update = CreateVertexUpdateDefinition(vertex, vertexType, myUpdate, copy, myTransaction, mySecurity);

                        updates.Add(vertex, update);
                    }
                }

                //force execution
                return ExecuteUpdates(groupedByTypeID, updates, myTransaction, mySecurity);
            }

            return Enumerable.Empty<IVertex>();
        }