Esempio n. 1
0
        public async Task <ActionResult> Update(
            [Bind(Prefix = "Entity.ID")] Guid id,
            [Bind(Prefix = "Entity.RowVersion")] byte[] rowVersion,
            [Bind(Prefix = "Args")] AnnotationEditArgs editArgs)
        {
            if (!ModelState.IsValid)
            {
                return(HttpStatusCodeResults.HttpBadRequest(ModelState));
            }

            var annotation = await Find <Annotation, Guid?>(id, "Entity", false);

            if (annotation == null)
            {
                return(HttpNotFound("Entity not found in database."));
            }

            if (ModelState.IsValid)
            {
                return(await DbUpdateResult(
                           annotation,
                           rowVersion,
                           editArgs.EndEditAction));
            }
            else
            {
                return(await Edit(annotation, editArgs));
            }
        }
        protected async Task <ActionResult> DbInsertResult <TEntity>(
            TEntity entity,
            string redirectUrl)
            where TEntity : class, IEntity
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (redirectUrl == null)
            {
                throw new ArgumentNullException("redirectUrl");
            }

            try
            {
                var entry = FaToolDbEntities.Entry(entity);
                entry.State = EntityState.Added;

                await FaToolDbEntities.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(HttpStatusCodeResults.HttpConflict(ex.Message));
            }
            catch (DbUpdateException ex1)
            {
                return(HttpStatusCodeResults.HttpInternalServerError(ex1));
            }

            return(Redirect(redirectUrl));
        }
Esempio n. 3
0
        public async Task <ActionResult> SetTerm(
            [Bind(Prefix = "Args")] AnnotationEditArgs editArgs)
        {
            if (!ModelState.IsValid)
            {
                return(HttpStatusCodeResults.HttpBadRequest(ModelState));
            }

            var annotation = Restore <Annotation>("Entity", true);
            var termQuery  = new TermQuery();

            TryUpdateModel(termQuery, "TermQuery");
            ModelState.Clear();

            if (string.IsNullOrWhiteSpace(editArgs.SelectedTermId) == false)
            {
                if (await FaToolDbEntities.Exists <Annotation>(x => x.FK_Protein == annotation.FK_Protein && x.FK_Term == editArgs.SelectedTermId))
                {
                    ModelState.AddModelError("Args.SelectedTermId", "Selected function term already mapped to protein.");
                    return(await SelectTerm(annotation, termQuery, editArgs));
                }
                else
                {
                    annotation.FK_Term = editArgs.SelectedTermId;
                }
            }
            else
            {
                ModelState.AddModelError("Args.SelectedTermId", "A term must be selected.");
                return(await SelectTerm(annotation, termQuery, editArgs));
            }

            return(await Edit(annotation, editArgs));
        }
Esempio n. 4
0
        public async Task <ActionResult> ChangeTerm(
            [Bind(Prefix = "Args")] AnnotationEditArgs editArgs)
        {
            if (!ModelState.IsValid)
            {
                return(HttpStatusCodeResults.HttpBadRequest(ModelState));
            }

            var annotation = Restore <Annotation>("Entity", true);

            return(await ChangeTerm(annotation, new TermQuery(), editArgs));
        }
        public async Task <ActionResult> Edit(
            string id,
            [Bind(Prefix = "Properties")] FaToolPersonalProperties properties)
        {
            var user = await UserManager.FindByIdAsync(id);

            if (user == null)
            {
                return(HttpNotFound("User not found."));
            }

            if (User.IsUserOrInRole(user.UserName, FaToolRoles.ADMIN) == false)
            {
                return(HttpStatusCodeResults.HttpUnauthorized());
            }

            if (ModelState.IsValid)
            {
                user.SetProperties(properties);

                IdentityResult result = await UserManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    return(Redirect(ShowUserAction(user).Url));
                }
                else
                {
                    AddErrors(result);

                    var model = new EditUserViewModel(
                        user,
                        properties,
                        GetCountryOptions(properties.Country));

                    return(View(model));
                }
            }
            else
            {
                var model = new EditUserViewModel(
                    user,
                    properties,
                    GetCountryOptions(properties.Country));

                return(View(model));
            }
        }
        public async Task <ActionResult> SearchFunctions(FunctionSearchQuery fsq)
        {
            if (ModelState.IsValid)
            {
                var query = from sp in FaToolDbEntities.GetProteinSearchValues(ProteinSearchOption.ProteinName, fsq.OrganismId)
                            join fp in FaToolDbEntities.GetProteinSearchValues(ProteinSearchOption.Function, fsq.OrganismId) on sp.ProteinID equals fp.ProteinID
                            where sp.Value == fsq.SearchName && fp.OntologyID == fsq.OntologyId
                            select new { id = fp.TermID, name = fp.TermName };

                var results = await query.ToArrayAsync();

                return(Json(results, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(HttpStatusCodeResults.HttpBadRequest(ModelState));
            }
        }
        public async Task <ActionResult> Edit(string id)
        {
            var user = await UserManager.FindByIdAsync(id);

            if (user == null)
            {
                return(HttpNotFound("User not found."));
            }

            if (User.IsUserOrInRole(user.UserName, FaToolRoles.ADMIN) == false)
            {
                return(HttpStatusCodeResults.HttpUnauthorized());
            }

            var model = new EditUserViewModel(
                user,
                GetCountryOptions(user.Country));

            return(View("Edit", model));
        }
Esempio n. 8
0
        public async Task <ActionResult> Insert(
            [Bind(Prefix = "Args")] AnnotationEditArgs editArgs)
        {
            if (!ModelState.IsValid)
            {
                return(HttpStatusCodeResults.HttpBadRequest(ModelState));
            }

            var annotation = Restore <Annotation>("Entity", false);

            if (ModelState.IsValid)
            {
                return(await DbInsertResult(
                           annotation,
                           editArgs.EndEditAction));
            }
            else
            {
                return(await Edit(annotation, editArgs));
            }
        }
Esempio n. 9
0
        public async Task <ActionResult> SelectTerm(
            [Bind(Prefix = "Args")] AnnotationEditArgs editArgs)
        {
            if (!ModelState.IsValid)
            {
                return(HttpStatusCodeResults.HttpBadRequest(ModelState));
            }

            var termQuery = new TermQuery();

            if (TryUpdateModel(termQuery, "TermQuery"))
            {
                var annotation = Restore <Annotation>("Entity", true);
                return(await SelectTerm(annotation, termQuery, editArgs));
            }
            else
            {
                var annotation = Restore <Annotation>("Entity", true);
                return(await ChangeTerm(annotation, termQuery, editArgs));
            }
        }
        public async Task <ActionResult> Get(string id)
        {
            var user = await UserManager.FindByIdAsync(id);

            if (user == null)
            {
                return(HttpNotFound("User not found."));
            }

            if (User.IsUserOrInRole(user.UserName, FaToolRoles.ADMIN) == false)
            {
                return(HttpStatusCodeResults.HttpUnauthorized());
            }

            var model = new UserViewModel(user);

            model.Properties.Actions.Add(EditUserAction(user));
            model.Properties.Actions.Add(ChangePasswordAction(user));
            model.Properties.Actions.Add(GrantRolesAction(user));
            model.Properties.Actions.Add(LockUserAction(user));
            model.Properties.Actions.Add(ShowUserListAction());

            return(View("User", model));
        }