Esempio n. 1
0
        public async Task <ActionResult> Create(string accountName, ContainerCreateModel model)
        {
            var account = await _accountDbCommand.FindByNameAsync(accountName);

            if (account == null)
            {
                return(HttpNotFound());
            }
            if (account.Owner != User.Identity.Name)
            {
                return(new HttpUnauthorizedResult());
            }

            if (!ModelState.IsValid)
            {
                return(PartialView("_Create", model));
            }

            if (await _containerDbCommand.ExistsAsync(account, model.Name))
            {
                ModelState.AddModelError("Name", "この名前はすでに使用されています。");
                return(PartialView("_Create", model));
            }

            var container = account.CreateContainer(model.Name);

            Mapper.Map(model, container);

            await _containerDbCommand.SaveAsync(container);

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Esempio n. 2
0
        public async Task <IContainer> AddAsync(ContainerCreateModel contianerModel)
        {
            var container = new Container()
            {
                Name = contianerModel.Name
            };

            _dbContext.Containers.Add(container);
            await _dbContext.SaveChangesAsync();

            return(container);
        }
        public async Task <IActionResult> AddContainerAsync([FromBody] ContainerCreateModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var container = await _containerStore.AddAsync(model);

            var containerModel = ModelMapper.ToViewModel(container);

            return(Ok(containerModel));
        }
        public async Task <IActionResult> UpdateContainerAsync(string id, [FromBody] ContainerCreateModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var container = await _containerStore.GetAsync(id);

            if (container == null)
            {
                return(NotFound());
            }

            container.Name = model.Name;

            var updatedContainer = await _containerStore.UpdateAsync(id, container);

            var updatedContainerModel = ModelMapper.ToViewModel(updatedContainer);

            return(Ok(updatedContainerModel));
        }
Esempio n. 5
0
 public async Task <IContainer> AddAsync(ContainerCreateModel containerModel)
 {
     return(await Task.FromResult(new ContainerTest()));
 }