Exemple #1
0
        // Add is overridden because we might need to set IsDeleted = false on an existing record
        // instead of actually inserting a new user.
        public override IViewModel <User, long> Add(BaseInputModel <User, long> input)
        {
            Auth.AuthorizeAdd();
            var uinput = input as UserInputModel;

            Logger.Information($"Adding user {uinput?.Username}.");
            var inactiveUser = Repo.FindOne <User>(Specification <User> .Start(u => u.Username == uinput.Username), incSoftDel: true, track: true);

            if (inactiveUser != null)
            {
                Logger.Information($"User was inactive, Id:{inactiveUser.Id}. Trying to reactivate.");
                if (!inactiveUser.IsDeleted)
                {
                    throw new InvalidInputException($"User {inactiveUser.Id} already exists.");
                }
                Logger.Information($"Reactivating {typeof(User).FullName}");
                Validator.Validate(input);
                inactiveUser.IsDeleted = false;
                //Repo.AddOrUpdate(inactiveUser);
                Repo.Save(true);
                Logger.Information($"Reactivated: {!inactiveUser.IsDeleted}.");
                return(Mapper.Map <IViewModel <User> >(inactiveUser));
            }
            else
            {
                return(base.Add(input));
            }
        }
Exemple #2
0
 public static BaseInputModel SupplementInPutModel(BaseInputModel obj, string MethodStr)
 {
     obj.partnerid = "miaozhilv";
     obj.method    = MethodStr;
     obj.reqtime   = DateTime.Now.ToString("yyyyMMddHHmmss");
     obj.sign      = MD5Helper.MD5Helper.GetSign(obj.partnerid, obj.method, obj.reqtime);
     return(obj);
 }
Exemple #3
0
        /// <summary>
        /// This method performs the validation of the input model & provides the
        /// details of the error in the view model
        /// </summary>
        /// <param name="inputModel"></param>
        /// <param name="viewModel"></param>
        private void ValidateModel(BaseInputModel inputModel, BaseViewModel viewModel)
        {
            var results = new List <ValidationResult>();
            var context = new ValidationContext(inputModel, null, null);

            if (!Validator.TryValidateObject(inputModel, context, results, true))
            {
                viewModel.Error = new ErrorModel();
                viewModel.Error.AddRange(results.Select(vr => vr.ErrorMessage));
            }
        }
Exemple #4
0
 /// <summary>
 /// 请求空铁无忧接口
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="methodStr"></param>
 /// <returns></returns>
 public static BaseInputModel SupplementInPutModel(BaseInputModel obj, string methodStr)
 {
     obj.partnerid = "mzl_formal";
     if (methodStr == "train_query")
     {
         obj.partnerid = "miaozhilv";
     }
     obj.method  = methodStr;
     obj.reqtime = DateTime.Now.ToString("yyyyMMddHHmmss");
     obj.sign    = MD5Helper.GetSign(obj.partnerid, obj.method, obj.reqtime);
     return(obj);
 }
        // TODO what if target null?
        public virtual IViewModel <T, long> Update(BaseInputModel <T, long> input)
        {
            Auth.AuthorizeUpdate();
            Logger.Information($"Updating {typeof(T).FullName} Id:{input.Id}.");
            Validator.Validate(input);
            var existingObj = Repo.FindOne(Specs.ById <T>(input.Id).And(Auth.GenerateFilterUpdate()), track: true);

            Mapper.Map(input, existingObj);
            Repo.Save();
            Logger.Information($"Update of {typeof(T).FullName} Id:{input.Id} complete.");
            return(Mapper.Map <IViewModel <T> >(existingObj));
        }
        public virtual IViewModel <T, long> Add(BaseInputModel <T, long> input)
        {
            Auth.AuthorizeAdd();
            Logger.Information($"Add {typeof(T).FullName}");
            Validator.Validate(input);
            var newObj = Mapper.Map <T>(input);

            Repo.AddEntity(newObj);
            Repo.Save();
            Logger.Information($"Added {typeof(T).FullName} Id:{newObj?.Id}");
            return(Mapper.Map <IViewModel <T> >(newObj));
        }
Exemple #7
0
        static void Main(string[] args)
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                ConnetSocket(socket);

                UserInput();

                var userInput = new BaseInputModel(int.Parse(_rowBegin),
                                                   int.Parse(_rowEnd),
                                                   int.Parse(_columnBegin),
                                                   int.Parse(_columnEnd),
                                                   _matrixLeft,
                                                   _matrixRight);

                string json = JsonConvert.SerializeObject(userInput);
                byte[] data = Encoding.Unicode.GetBytes(json);
                socket.Send(data);

                data = new byte[512];

                var decodedResult = Decoder(socket, data);

                Console.WriteLine(decodedResult);
                var result = JsonConvert.DeserializeObject <List <List <int> > >(decodedResult);
                OutputResult(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
            finally
            {
                socket.Shutdown(SocketShutdown.Both);
                socket.Close();
            }

            Console.ReadKey();
        }
Exemple #8
0
        static void Main(string[] args)
        {
            try
            {
                InitializeData();

                StartPortListening();

                while (true)
                {
                    Socket handler = serverSideSocket.Accept();

                    var inputData = Decoder(handler);

                    Console.WriteLine(DateTime.Now.ToShortTimeString() + ": " + inputData);
                    BaseInputModel userInput = JsonConvert.DeserializeObject <BaseInputModel>(inputData);

                    var matrixA = GetMatrix(userInput.MatrixLeftName, userInput.RowBegin, userInput.RowEnd, userInput.ColumnBegin, userInput.ColumnEnd);
                    var matrixB = GetMatrix(userInput.MatrixRightName, userInput.RowBegin, userInput.RowEnd, userInput.ColumnBegin, userInput.ColumnEnd);

                    List <List <List <int> > > matrixes = new List <List <List <int> > >()
                    {
                        matrixA,
                        matrixB
                    };

                    SendData(matrixes, handler);

                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
            finally
            {
                CloseConnection();
            }
        }
Exemple #9
0
 public IViewModel <V_MyView, string> Add(BaseInputModel <V_MyView, string> input)
 {
     throw new NotImplementedException("View is read-only");
 }
 public BaseModelBuilder(BaseInputModel inputModel)
 {
     this.inputModel = inputModel;
 }