Ejemplo n.º 1
0
        public ActionResult Edit(UseCase useCase, List <int> actors, List <int> requirements)
        {
            var old = db.UseCases.Find(useCase.ID);

            old.Name        = useCase.Name;
            old.Description = useCase.Description;

            if (actors != null)
            {
                for (int i = 0; i < actors.Count; i++)
                {
                    UseCaseActor useCaseActor = new UseCaseActor();
                    useCaseActor.ID_Actor   = actors[i];
                    useCaseActor.ID_UseCase = old.ID;
                    db.UseCaseActors.Add(useCaseActor);
                }
            }
            if (requirements != null)
            {
                for (int i = 0; i < requirements.Count; i++)
                {
                    UseCaseRequirement useCaseRequirement = new UseCaseRequirement();
                    useCaseRequirement.ID_Requirement = requirements[i];
                    useCaseRequirement.ID_UseCase     = old.ID;
                    db.UseCaseRequirements.Add(useCaseRequirement);
                }
            }

            try
            {
                db.Entry(old).State = EntityState.Modified;
                db.SaveChanges();
                NotificationSystem.SendNotification(EnumNotification.EDIT_USECASE, "/UseCase");
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }


            List <int> actorsList = new List <int>();

            foreach (UseCaseActor useCaseActor in useCase.UseCaseActors)
            {
                actorsList.Add(useCaseActor.ID);
            }

            ViewBag.actors       = new MultiSelectList(GetActors(old), "ID", "Name");
            ViewBag.requirements = new MultiSelectList(GetRequirements(old), "ID", "Text");

            return(View(useCase));
        }
Ejemplo n.º 2
0
        public ActionResult AddActors()
        {
            List <int> actors    = (List <Int32>)Session["actors"];
            int        useCaseID = db.UseCases.OrderByDescending(i => i.ID).First().ID;

            foreach (int i in actors)
            {
                UseCaseActor caseActor = new UseCaseActor();
                caseActor.ID_Actor   = i;
                caseActor.ID_UseCase = useCaseID;
                db.UseCaseActors.Add(caseActor);
            }

            db.SaveChanges();

            return(RedirectToAction("AddRequirements"));
        }
Ejemplo n.º 3
0
        public async Task <UCActorDto> Handle(AddActorCommand command, CancellationToken cancellationToken)
        {
            var entity = await _context.Actors
                         .Where(x => x.Name.ToLower() == command.Name.ToLower())
                         .FirstOrDefaultAsync(cancellationToken);

            if (entity != null)
            {
                return(new UCActorDto {
                    Id = entity.Id, Name = entity.Name
                });
            }

            var uc = new UseCaseActor {
                Name = command.Name
            };

            _context.Actors.Add(uc);
            await _context.SaveChangesAsync(cancellationToken);

            return(new UCActorDto {
                Id = uc.Id, Name = uc.Name
            });
        }