Example #1
0
        public async Task <IHttpActionResult> Update([FromBody] StorageDTO StorageDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var entity = await StorageService.FindOneAsync(StorageDto.Id);

            entity            = StorageDto.ToEntity(entity);
            entity.LastUserId = User.Identity.GetUserId();
            entity.LastTime   = DateTime.Now;
            await StorageService.UpdateAsync(entity);

            return(Ok(entity.ToModel()));
        }
Example #2
0
        public async Task <IHttpActionResult> Create([FromBody] StorageDTO StorageDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var entity = StorageDto.ToEntity();
            var roleId = MBHelper.GetUserRoleId(User);

            if (roleId == (int)RoleType.Member)
            {
                entity.StorageType = (int)StorageType.Member;
            }
            else
            {
                entity.StorageType = (int)StorageType.System;
            }
            entity.CreateUserId = User.Identity.GetUserId();
            entity.CreateTime   = DateTime.Now;
            await StorageService.InsertAsync(entity);

            return(Ok(entity.ToModel()));
        }