Exemplo n.º 1
0
        private async Task <ObjectType> AssignObjectType(ObjectTypeViewModel objectTypeViewModel)
        {
            ObjectType objectType = new ObjectType
            {
                ControlType   = objectTypeViewModel.ControlType,
                ControlTypeId = objectTypeViewModel.ControlTypeId,
                Data          = objectTypeViewModel.Data,
                FormObject    = objectTypeViewModel.FormObject,
                Name          = objectTypeViewModel.Name,
                ObjectTypeId  = objectTypeViewModel.ObjectTypeId,
                Options       = objectTypeViewModel.Options,
                StartEnd      = objectTypeViewModel.StartEnd,
            };

            //Only read from the stream if this is an image
            if (objectTypeViewModel.ControlType.Name == "Image")
            {
                using (var memoryStream = new MemoryStream())
                {
                    await objectTypeViewModel.Image.CopyToAsync(memoryStream);

                    objectType.Image = memoryStream.ToArray();
                }
            }
            return(objectType);
        }
Exemplo n.º 2
0
        private bool CheckImage(ObjectTypeViewModel objectTypeViewModel)
        {
            objectTypeViewModel.ControlType = _context.ControlTypes.Where(x => x.ControlTypeId == objectTypeViewModel.ControlTypeId).SingleOrDefault();

            //If this is meant to be an image but another file type is used
            if (objectTypeViewModel.ControlType.Name == "Image" &&
                HttpPostedFileBaseExtensions.IsImage(objectTypeViewModel.Image) == false)
            {
                ModelState.AddModelError("", "Please select an image file");
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 3
0
        private ObjectTypeViewModel AssignViewModel(ObjectType objectType)
        {
            ObjectTypeViewModel objectTypeViewModel = new ObjectTypeViewModel
            {
                ControlType   = objectType.ControlType,
                ControlTypeId = objectType.ControlTypeId,
                Data          = objectType.Data,
                FormObject    = objectType.FormObject,
                ImageBytes    = objectType.Image,
                Name          = objectType.Name,
                ObjectTypeId  = objectType.ObjectTypeId,
                Options       = objectType.Options,
                StartEnd      = objectType.StartEnd,
            };

            return(objectTypeViewModel);
        }
Exemplo n.º 4
0
        // GET: ObjectTypes/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ObjectType objectType = await _context.ObjectTypes.Include(f => f.ControlType).SingleOrDefaultAsync(m => m.ObjectTypeId == id);

            ObjectTypeViewModel objectTypeViewModel = AssignViewModel(objectType);

            if (objectTypeViewModel == null)
            {
                return(NotFound());
            }
            ViewData["ControlTypeId"] = new SelectList(_context.ControlTypes, "ControlTypeId", "Name", objectType.ControlTypeId);
            return(View(objectTypeViewModel));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("ObjectTypeId,Name,Data,Image,Options,StartEnd,ControlTypeId")] ObjectTypeViewModel objectTypeViewModel)
        {
            ObjectType objectType = new ObjectType {
            };

            if (ModelState.IsValid)
            {
                //Only save if the image is valid or not required
                if (CheckImage(objectTypeViewModel))
                {
                    objectType = await AssignObjectType(objectTypeViewModel);

                    _context.Add(objectType);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["ControlTypeId"] = new SelectList(_context.ControlTypes, "ControlTypeId", "Name", objectType.ControlTypeId);
            return(View(objectTypeViewModel));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("ObjectTypeId,Name,Data,Image,Options,StartEnd,ControlTypeId")] ObjectTypeViewModel objectTypeViewModel)
        {
            ObjectType objectType = new ObjectType {
            };

            if (id != objectTypeViewModel.ObjectTypeId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //Only update if the image is valid or not required
                    if (CheckImage(objectTypeViewModel))
                    {
                        objectType = await AssignObjectType(objectTypeViewModel);

                        _context.Update(objectType);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ObjectTypeExists(objectType.ObjectTypeId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            ViewData["ControlTypeId"] = new SelectList(_context.ControlTypes, "ControlTypeId", "Name", objectType.ControlTypeId);
            return(View(objectTypeViewModel));
        }
Exemplo n.º 7
0
        public async Task <HttpResponseMessage> Update(ObjectTypeViewModel vm)
        {
            var entity = Mapper.CreateInstanceAndMapProperties <ObjectType>(vm);

            return(await UpdateInternal(entity));
        }
Exemplo n.º 8
0
        public async Task <HttpResponseMessage> Create([FromUri] Guid parentFolderId, ObjectTypeViewModel vm)
        {
            var entity = new ObjectType
            {
                Name        = vm.Name,
                Description = vm.Description,
                EntityType  = vm.EntityType,
                OwnerId     = User.Identity.Name
            };

            return(await CreateInternal(entity, parentFolderId));
        }
Exemplo n.º 9
0
 public async Task <HttpResponseMessage> GetSubTree([FromUri] ObjectTypeViewModel vm)
 {
     return(await GetSubTreeInternal(vm.Id));
 }
 public ObjectTypeWindow()
 {
     InitializeComponent();
     this.DataContext = ViewModel = new ObjectTypeViewModel();
 }