private void addFile(Project proj, WJPUser curUser, HttpPostedFileBase file, string FileType)
        {
            string needExt;
            if (FileType == "Source")
                needExt = ".java";
            else
            if (FileType == "Library")
                needExt = ".jar";
            else
                needExt = "";

            if (file != null && file.ContentLength > 0)
            {
                if (needExt == "" || Path.GetExtension(file.FileName) == needExt)
                {
                    string fileName = Path.GetFileName(file.FileName);
                    bool found = false;
                    if (FileType == "Source")
                        foreach (SourceFile f in proj.SourceFiles)
                        {
                            if (f.FileName == fileName) { found = true; break; }
                        }
                    else
                    if (FileType == "Library")
                        foreach (LibraryFile f in proj.LibraryFiles)
                        {
                            if (f.FileName == fileName) { found = true; break; }
                        }
                    else
                        foreach (DataFile f in proj.DataFiles)
                        {
                            if (f.FileName == fileName) { found = true; break; }
                        }

                    if (!found)
                    {
                        string path = Path.Combine(
                            Server.MapPath("~/Projects/") + proj.ProjectID + "/" + FileType, fileName);
                        file.SaveAs(path);

                        ProjectFile f;
                        if (FileType == "Source")
                            f = new SourceFile();
                        else
                        if (FileType == "Library")
                            f = new LibraryFile();
                        else
                            f = new DataFile();

                        f.Adder = curUser;
                        f.Modifier = curUser;
                        f.FileName = fileName;
                        f.Project = proj;

                        curUser.LastChangesDate = DateTime.Now;
                        curUser.LastProject = proj;

                        if (FileType == "Source")
                        {
                            curUser.SourcesAdded++;
                            proj.SourceFiles.Add( (SourceFile)f );
                            profileDB.SourceFiles.Add( (SourceFile)f );
                        } else

                        if (FileType == "Library")
                        {
                            curUser.LibrariesAdded++;
                            proj.LibraryFiles.Add((LibraryFile)f);
                            profileDB.LibraryFiles.Add((LibraryFile)f);
                        }
                        else
                        {
                            curUser.DataAdded++;
                            proj.DataFiles.Add((DataFile)f);
                            profileDB.DataFiles.Add((DataFile)f);
                        }

                        proj.LastChangesDate = DateTime.Now;
                        proj.LastChanger = curUser;

                        profileDB.Entry(curUser).State = EntityState.Modified;
                        profileDB.Entry(proj).State = EntityState.Modified;
                        profileDB.SaveChanges();
                    }
                    else
                        ViewBag.FileTypeError = "File with such name already exists";
                }
                else
                    ViewBag.FileTypeError = "Uploaded file isn't " + FileType + " file";
            }
        }
        bool checkRole(WJPUser user, Project proj)
        {
            if (Roles.GetRolesForUser(User.Identity.Name).Contains("Administrator"))
            {
                ViewBag.Mode = "God";
                return true;
            }

            if (proj.Owner == user)
            {
                ViewBag.Mode = "Owner";
                return true;
            }

            if (user.AllowedProjects.Contains(proj))
            {
                ViewBag.Mode = "User";
                return true;
            }
            return false;
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, "question", "answer", true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    WJPUser newUser = new WJPUser();
                    newUser.UserName = model.UserName;
                    profileDB.Users.Add(newUser);
                    profileDB.SaveChanges();
                    printLog("User '" + model.UserName + "' registred");
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }