public GroupViewModel CreateViewModel(DataTransferViewModel dataTransfer)
		{
			GroupViewModel viewModel = new GroupViewModel();
			//if (dataTransfer.EnumViewModelType.ToString().Contains("ADMIN"))
			switch (dataTransfer.EnumViewModelType)
			{
				
				case EnumViewModel.HOME_REGISTER:
					break;
                case EnumViewModel.HOME_UPLOAD:
                    viewModel.SOLUTIONSModel = retrieveSOLUTIONSViewModel(dataTransfer);
                    break;
                case EnumViewModel.HOME_UPLOAD_SUCCESSFULL:
                case EnumViewModel.HOME_DSSOLUTION:
                case EnumViewModel.HOME_SOLUTION:
                case EnumViewModel.HOME_METHOD:
                case EnumViewModel.HOME_CLASS:
                    viewModel.SOLUTIONSModel = retrieveSOLUTIONSViewModel(dataTransfer);
                    switch (dataTransfer.EnumViewModelType)
                    {
                        case EnumViewModel.HOME_METHOD:
                            viewModel.METHODSModel = retrieveMETHODSViewModel(dataTransfer);
                            break;
                        case EnumViewModel.HOME_CLASS:
                            viewModel.CLASSESModel = retrieveCLASSESViewModel(dataTransfer);
                            break;
                    }
                    break;
                case EnumViewModel.HOME_DETAILOF_NGUOIDUNG:
                    viewModel.NGUOIDUNGModel = RetrieveDetailOfNguoiDungViewModel(dataTransfer);
                    break;
			}
			return viewModel;
		}
 public ActionResult Index()
 {
     var data = new DataTransferViewModel
     {
         EnumViewModelType = EnumViewModel.HOME_UPLOAD
     };
     return View("Index", CreateViewModel(data));
 }
 public ActionResult SelectMETHODS(int id)
 {
     var data = new DataTransferViewModel
     {
         EnumViewModelType = EnumViewModel.HOME_METHOD,
         IDMethod = id
     };
     return View("SelectMethod", CreateViewModel(data));
 }
 public ActionResult SelectCLASSES(int id)
 {
     var data = new DataTransferViewModel
     {
         EnumViewModelType = EnumViewModel.HOME_CLASS,
         IDClass = id
     };
     return View("SelectClass", CreateViewModel(data));
 }
 public ActionResult Solution(int id)
 {
     var data = new DataTransferViewModel
     {
         IDSolution = id,
         EnumViewModelType = EnumViewModel.HOME_SOLUTION
     };
     return View("Solution", CreateViewModel(data));
 }
 public ActionResult SelectSOLUTIONSByNguoiDang(Guid idnguoidang, int page = 1)
 {
     var data = new DataTransferViewModel
     {
         IDNguoiDang = idnguoidang,
         EnumViewModelType = EnumViewModel.HOME_DSSOLUTION,
         CurrentPage = page
     };
     return View("DanhSachSoln", CreateViewModel(data));
 }
        /// <summary>
        /// Action when user upload a solution to analyze
        /// </summary>
        /// <param name="forms"></param>
        /// <returns></returns>
        public ActionResult UploadSolution(FormCollection forms)
        {
            var file = Request.Files["Solution"];
            _userID = forms.GetValues("UserID")[0];
            var result = true;
            var errorText = "";
            var view = "Index";
            EnumViewModel viewModel = EnumViewModel.HOME_UPLOAD;

            if (file.ContentLength != 0)
            {
                // Upload solution to host
                result = UploadFile(file, "/Content/Projects/" + _userID + "/", ref errorText);
            }

            if (result)
            {
                view = "DanhSachSoln";
                viewModel = EnumViewModel.HOME_UPLOAD_SUCCESSFULL;
                // Analyze project
                lstSol = new List<string>();
                var solnName = file.FileName.Split(new char[] { '.' })[0];
                GetFiles(Server.MapPath("/Content/Projects/" + _userID + "/" + solnName), WebConfiguration.ProjectType, ref lstSol);
                _solnPath = this.lstSol[0];
                // Init Solution
                _solStructure = new SolnStructure
                {
                    Name = solnName,
                    Projects = new List<ProjStructure>(),
                    Path = Path.GetDirectoryName(_solnPath)
                };
                // Analyze other projects in solution
                result = Analyzeprojects(ref errorText);
                if (result)
                {
                    Insert_Soln();
                }
            }
            
            var data = new DataTransferViewModel
            {
                IDNguoiDang = Guid.Parse(_userID),
                Added = result,
                ErrorText = errorText,
                EnumViewModelType = viewModel
            };
            return View(view, CreateViewModel(data));
        }
 public ActionResult CapNhatThongTinTaiKhoan(FormCollection forms/*, bool captchaValid*/)
 {
     var nguoiDungInfo = new EditNGUOIDUNGViewModel
     {
         ID = Guid.Parse(forms.GetValues("NguoiDung_ID")[0])
     };
     var user = Membership.GetUser(nguoiDungInfo.ID);
     user.Email = forms.GetValues("NguoiDung_Email")[0];
     Membership.UpdateUser(user);
     
     var data = new DataTransferViewModel
     {
         EnumViewModelType = EnumViewModel.HOME_DETAILOF_NGUOIDUNG,
         UserName = forms.GetValues("NguoiDung_UserName")[0],
         Updated = true
     };
     return View("ThongTinNguoiDung", CreateViewModel(data));
 }
 public ActionResult ThongTinNguoiDung(string username)
 {
     var data = new DataTransferViewModel
     {
         EnumViewModelType = EnumViewModel.HOME_DETAILOF_NGUOIDUNG,
         UserName = username
     };
     return View("ThongTinNguoiDung", CreateViewModel(data));
 }
		public PROJECTSViewModel retrievePROJECTSViewModel(DataTransferViewModel dataTransfer)
		{
			List<PROJECT> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDSolution != -1)
			{
				lst = _repPROJECTS.SelectBySolution(dataTransfer.IDSolution);
				totalitem = _repPROJECTS.GetTotalItemBySolution(dataTransfer.IDSolution);
			}
			else
			{
				lst = _repPROJECTS.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repPROJECTS.GetTotalItem();
			}
			return new PROJECTSViewModel
			{
				GetModel = new GetPROJECTSViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddPROJECTSViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditPROJECTSViewModel
				{
					ID = dataTransfer.IntEditID
				},
				ReferKeys = new PROJECTSReferKeys()
				{
					IDSolution = dataTransfer.IDSolution,
				}
			};
		}
        // **************************************
        // URL: /Account/Register
        // **************************************

        public ActionResult Register()
        {
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_REGISTER
            };
            return View(CreateViewModel(data));
        }
		public NGUOIDUNGViewModel retrieveNGUOIDUNGViewModel(DataTransferViewModel dataTransfer)
		{
			return new NGUOIDUNGViewModel
			{
				GetModel = new GetNGUOIDUNGViewModel
				{
					LstObjModel = _repNGUOIDUNG.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage, dataTransfer.Role),
					TotalItem = _repNGUOIDUNG.GetTotalItem(dataTransfer.Role),
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddNGUOIDUNGViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditNGUOIDUNGViewModel
				{
					ID = dataTransfer.EditIDNguoiDung,
					Edited = dataTransfer.Updated
				}
			};
		}
		public INVARIANTSViewModel retrieveINVARIANTSViewModel(DataTransferViewModel dataTransfer)
		{
			List<INVARIANT> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDMethod != -1)
			{
                lst = _repINVARIANTS.SelectByClass(dataTransfer.IDMethod);
				totalitem = _repINVARIANTS.GetTotalItemByMethod(dataTransfer.IDMethod);
			}
			else
			{
				lst = _repINVARIANTS.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repINVARIANTS.GetTotalItem();
			}
			return new INVARIANTSViewModel
			{
				GetModel = new GetINVARIANTSViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddINVARIANTSViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditINVARIANTSViewModel
				{
                    ID = dataTransfer.IntEditID
				},
				ReferKeys = new INVARIANTSReferKeys()
				{
					IDMethod = dataTransfer.IDMethod,
				}
			};
		}
		public SOLUTIONSViewModel retrieveSOLUTIONSViewModel(DataTransferViewModel dataTransfer)
		{
            List<SOLUTION> lst = null;
            if (dataTransfer.IDNguoiDang != Guid.Parse("11112222-1111-1111-1111-111122223333"))
            {
                lst = _repSOLUTIONS.SelectByNguoiDang(dataTransfer.IDNguoiDang);
            }
            else if (dataTransfer.IDSolution != -1)
            {
                lst = _repSOLUTIONS.RetrieveByID(dataTransfer.IDSolution);
            }
            else
            {
                lst = _repSOLUTIONS.SelectAll();
            }
			return new SOLUTIONSViewModel
			{
				GetModel = new GetSOLUTIONSViewModel
				{
					LstObjModel = lst,
					TotalItem = lst.Count,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddSOLUTIONSViewModel
				{
					Added = dataTransfer.Added,
                    ErrorText = dataTransfer.ErrorText
				},
				EditModel = new EditSOLUTIONSViewModel
				{
                    ID = dataTransfer.IntEditID,
					Edited = dataTransfer.Updated
				}
			};
		}
		public METHODSViewModel retrieveMETHODSViewModel(DataTransferViewModel dataTransfer)
		{
			List<METHOD> lst = null;
			if (dataTransfer.IDClass != -1)
			{
				lst = _repMETHODS.SelectByClass(dataTransfer.IDClass);
			}
			else if (dataTransfer.IDMethod != -1)
            {
                lst = _repMETHODS.RetrieveByID(dataTransfer.IDMethod);
            }
			else
            {
                lst = _repMETHODS.SelectAll();
			}
			return new METHODSViewModel
			{
				GetModel = new GetMETHODSViewModel
				{
					LstObjModel = lst,
					TotalItem = lst.Count,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddMETHODSViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditMETHODSViewModel
				{
                    ID = dataTransfer.IntEditID
				},
				ReferKeys = new METHODSReferKeys()
				{
					IDClass = dataTransfer.IDClass,
				}
			};
		}
		public CLASSESViewModel retrieveCLASSESViewModel(DataTransferViewModel dataTransfer)
		{
			List<CLASS> lst = null;
			int totalitem = -1;
			if (dataTransfer.IDProject != -1)
			{
				lst = _repCLASSES.SelectByProject(dataTransfer.IDProject);
				totalitem = _repCLASSES.GetTotalItemByProject(dataTransfer.IDProject);
			}
            else if (dataTransfer.IDClass != -1)
            {
                lst = _repCLASSES.RetrieveByID(dataTransfer.IDClass);
            }
			else {
				lst = _repCLASSES.SelectPaging(dataTransfer.CurrentPage, dataTransfer.ProductsPerPage);
				totalitem = _repCLASSES.GetTotalItem();
			}
			return new CLASSESViewModel
			{
				GetModel = new GetCLASSESViewModel
				{
					LstObjModel = lst,
					TotalItem = totalitem,
					CurrentPage = dataTransfer.CurrentPage
				},
				AddModel = new AddCLASSESViewModel
				{
					Added = dataTransfer.Added
				},
				EditModel = new EditCLASSESViewModel
				{
                    ID = dataTransfer.IntEditID
				},
				ReferKeys = new CLASSESReferKeys()
				{
					IDProject = dataTransfer.IDProject,
				}
			};
		}
        public ActionResult Register(FormCollection forms/*, bool captchaValid*/)
        {
            string errorText = "";
            var nguoiDungInfo = new AddNGUOIDUNGViewModel
            {
                Info = new NGUOIDUNGInfo
                {
                    BaseInfo = new NGUOIDUNGBaseInfo
                    {
                        UserName = forms.GetValues("NguoiDung_UserName")[0],
                        Password = forms.GetValues("NguoiDung_Password")[0],
                        Email = forms.GetValues("NguoiDung_Email")[0]
                    }
                }
            };
            var result = _repNGUOIDUNG.Insert(ref nguoiDungInfo, ref errorText);
            if (result)
            {
                CreateUserFolder(nguoiDungInfo.Info.BaseInfo.ID);
                // Insert successfully, then create new folder with folder name is the id of new user
                FormsService.SignIn(forms.GetValues("NguoiDung_UserName")[0], false /* createPersistentCookie */);
                return RedirectToAction("Index", "Home");
            }

            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_REGISTER
            };
            return View(CreateViewModel(data));
        }
 public NGUOIDUNGViewModel RetrieveDetailOfNguoiDungViewModel(DataTransferViewModel dataTransfer)
 {
     return new NGUOIDUNGViewModel
     {
         GetModel = new GetNGUOIDUNGViewModel
         {
             LstObjModel = _repNGUOIDUNG.RetrieveByUserName(dataTransfer.UserName)
         },
         AddModel = new AddNGUOIDUNGViewModel
         {
             Added = dataTransfer.Added
         },
         EditModel = new EditNGUOIDUNGViewModel
         {
             Edited = dataTransfer.Updated
         }
     };
 }