Пример #1
0
        public ActionResult SaveMovement()
        {
            //For several movements at same time should use json
            //string[] movs = operations.Split('|');

            string operations = null;
            operations = HttpContext.Request.Form[0].ToString();

            if (operations == null)
                return View();

            string[] vars = operations.ToString().Split(';');
            //    var sendstr = "-1;true;" + ";" + mtype + ";" + cattype + ";" + subcattype + ";" + movamount + ";" + movdescription + ";" + dipckerdate;
            using (SGFEntitiess accM = new SGFEntitiess())
            {
                AccountDataModel acc = (AccountDataModel)Session["accountOnline"];
                AccountModel user = (AccountModel)Session["userOnline"];

                Int32? subcat = null;
                try{
                    subcat = Int32.Parse(vars[4]);
                }
                catch(Exception e){}

                //Add new Movement
                SGF_T_ACCOUNT_MOVEMENT accMov = SGF_T_ACCOUNT_MOVEMENT.CreateSGF_T_ACCOUNT_MOVEMENT(Int32.Parse(vars[0]), acc.Account_Id, Int32.Parse(vars[2]), Int32.Parse(vars[3]), subcat, (decimal)Double.Parse(vars[5]), vars[6].ToString(), user.Name.ToString(), DateTime.Parse(vars[7]));

                accM.AddToSGF_T_ACCOUNT_MOVEMENT(accMov);

                //commit changes
                accM.SaveChanges();
            }

            return View();
        }
Пример #2
0
        private void CreateAccount(int AccountId, string AccountNumber, string AccountName,
                                    string BankName, string OtherInfo, out bool status)
        {
            using (SGFEntitiess sessionAccount = new SGFEntitiess())
            {
                AccountModel user = (AccountModel)Session["userOnline"];

                //Valida se existe já conta registada para este User
                var result = from n in sessionAccount.SGF_T_ACCOUNT
                                join n2 in sessionAccount.SGF_T_ACCOUNT_USER on n.ACCOUNT_ID equals n2.ACCOUNT_ID
                                where n2.USER_ID == user.UserId && n.ACCOUNT_NUMBER == AccountNumber
                                select n;
                result.ToList();

                //Já existe a conta em questão
                if (result.SingleOrDefault() != null)
                {
                    SGF_T_ACCOUNT acc = result.SingleOrDefault();
                    acc.ACCOUNT_NAME = AccountName;
                    acc.BANK_NAME = BankName;
                    acc.OTHER_INFO = OtherInfo;
                }
                else
                {
                    //Add new Account
                    SGF_T_ACCOUNT acc =  SGF_T_ACCOUNT.CreateSGF_T_ACCOUNT(-1, AccountNumber, 0, AccountName, BankName, OtherInfo);
                    //SGF_T_ACCOUNT acc = SGF_T_ACCOUNT.CreateSGF_T_ACCOUNT(-1, AccountNumber,0);//so os obrigatorios
                    sessionAccount.AddToSGF_T_ACCOUNT(acc);
                    //Add new Account to User
                    SGF_T_ACCOUNT_USER accUser = SGF_T_ACCOUNT_USER.CreateSGF_T_ACCOUNT_USER(acc.ACCOUNT_ID, user.UserId, 1);
                    sessionAccount.AddToSGF_T_ACCOUNT_USER(accUser);
                }
                //commit changes
                sessionAccount.SaveChanges();

            }

            status = true;
            return;
        }
Пример #3
0
        private void CreateUser(string email, string password, string name, int nationality, 
                                int languagepref, out MembershipCreateStatus status)
        {
            using (SGFEntitiess sessionUser = new SGFEntitiess())
            {
                //Valida se existe já User registado
                var result = from i in sessionUser.SGF_T_USER
                             where i.EMAIL == email
                             select i;
                //Já existe o email em questão
                if (result.SingleOrDefault() != null)
                {
                    status = MembershipCreateStatus.DuplicateUserName;
                    return;
                }

                string hashPassword = EncryptSHA256(password);
                SGF_T_USER s = SGF_T_USER.CreateSGF_T_USER(-1, name, hashPassword, email, DateTime.Now, nationality, languagepref);
                sessionUser.AddToSGF_T_USER(s);
                sessionUser.SaveChanges();

                AccountModel userOnline = new AccountModel(s.USER_ID, s.NAME, s.EMAIL);
                Session["userOnline"] = userOnline;
            }

            status = MembershipCreateStatus.Success;
            return;
        }