Ejemplo n.º 1
0
        public DataToSend Processing(DataToSend inputData)
        {
            ISocketService  socketService   = new SocketService();
            DataToSend      outputData      = new DataToSend();
            LoginMap        loginMap        = new LoginMap();
            DeviceMap       deviceMap       = new DeviceMap();
            AccountMap      accountMap      = new AccountMap();
            RegistrationMap registrationMap = new RegistrationMap();

            if (inputData.Action == MessageSocketData.SocketObj.Action.Login)
            {
                Console.WriteLine("Login...");
                LoginDTO   loginDTO   = loginMap.MapTo(inputData.FirstObject as LoginSocket);
                DeviceDTO  deviceDTO  = deviceMap.MapTo(inputData.SecondObject as DeviceSocket);
                AccountDTO accountDTO = new AccountDTO();
                accountDTO             = socketService.CheckUser(loginDTO, deviceDTO);
                outputData.FirstObject = accountMap.MapFrom(accountDTO);
            }
            if (inputData.Action == MessageSocketData.SocketObj.Action.Registration)
            {
                Console.WriteLine("Registration...");
                RegistrationDTO registrationDTO = registrationMap.MapTo(inputData.FirstObject as RegistrationSocket);


                bool answer = socketService.GetRegistration(registrationDTO);
                outputData.Boolean = answer;
            }


            return(outputData);
        }
Ejemplo n.º 2
0
 public ActionResult Register(RegistrationDTO registrationDTO)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (var db = new Models.HacForoContainer())
             {
                 if (registrationDTO.IsValid(db, ModelState))
                 {
                     db.UserSet.Add(RegistrationMap.MapTo(registrationDTO));
                     db.SaveChanges();
                     return(RedirectToAction("Index", "Home"));
                 }
             }
         }
         else
         {
             ModelState.AddModelError("", "The data is not correct");
         }
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         throw;
     }
     return(View());
 }