Beispiel #1
0
        public virtual async Task <IHttpActionResult> Delete(Y id)
        {
            ///Generic olan gelen servisin Delete metoduna ilgili id
            ///ve token bilgisini okuyarak elde edilen User Id gönderilmiştir.
            var result = await _service.Delete(id, IdentityClaimsValues.UserId <Y>());

            ///Delete işleminin sonucunu kontrol eder.
            if (result.Message != Messages.Ok)
            {
                return(Content(HttpStatusCode.BadRequest, result));
            }

            return(Ok(result));
        }
        public async Task <IHttpActionResult> Update(UserUpdateDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await userService.Update(model, IdentityClaimsValues.UserId <Guid>());

            if (result.Message != Messages.Ok)
            {
                return(Content(HttpStatusCode.BadRequest, result));
            }

            return(Ok(result));
        }
Beispiel #3
0
        public virtual async Task <IHttpActionResult> Update(U model)
        {
            ///İlgili modelin şartlarını kontrol eder.
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ///Generic olan gelen servisin Update metoduna ilgili view model
            ///ve token bilgisini okuyarak elde edilen User Id gönderilmiştir.
            var result = await _service.Update(model, IdentityClaimsValues.UserId <Y>());

            ///Update işleminin sonucunu kontrol eder.
            if (result.Message != Messages.Ok)
            {
                return(Content(HttpStatusCode.BadRequest, result));
            }

            return(Ok(result));
        }
        public async Task <IHttpActionResult> AutoCodeGenerate(string screenCode = null)
        {
            var result = await _service.AutoCodeGenerate(screenCode, IdentityClaimsValues.UserId <Guid>());

            return(Ok(result));
        }
Beispiel #5
0
        public async Task <IHttpActionResult> Upload(Guid refId, string screenCode)
        {
            #region Condition

            /// Checks whether the parameters are null.
            if (refId == null || screenCode == null)
            {
                return(BadRequest(Messages.FUE0002));
            }

            /// Controls whether the screen code is in the <see cref="ScreenCodes"/> class.
            if (!typeof(ScreenCodes).GetFields().Any(x => x.Name == screenCode))
            {
                return(BadRequest(Messages.GNW0002));
            }

            /// Checks the media type for the file-s to be uploaded.
            if (!Request.Content.IsMimeMultipartContent())
            {
                return(Content(HttpStatusCode.UnsupportedMediaType, Messages.FUW0001));
            }
            #endregion

            /// `localPath` and `useCloud` is get from Web.Config.
            string localPath = HostingEnvironment.MapPath(ConfigurationManager.AppSettings["fileServiceLocalPath"]);
            bool   useCloud  = Convert.ToBoolean(ConfigurationManager.AppSettings["useCloud"]);

            var provider = new MultipartFormDataStreamProvider(localPath);

            try
            {
                /// Loads the files into the local storage.
                await Request.Content.ReadAsMultipartAsync(provider);

                /// Check is exist valid file.
                if (provider.FileData.Count == 0)
                {
                    return(BadRequest(Messages.FUE0001));
                }

                IList <FileDto> modelList = new List <FileDto>();

                foreach (MultipartFileData file in provider.FileData)
                {
                    string originalName = file.Headers.ContentDisposition.FileName;
                    if (originalName.StartsWith("\"") && originalName.EndsWith("\""))
                    {
                        originalName = originalName.Trim('"');
                    }
                    if (originalName.Contains(@"/") || originalName.Contains(@"\"))
                    {
                        originalName = Path.GetFileName(originalName);
                    }

                    FileDto fileDto = new FileDto
                    {
                        RefId        = refId,
                        ScreenCode   = screenCode,
                        OriginalName = Path.GetFileNameWithoutExtension(originalName),
                        StorageName  = Path.GetFileName(file.LocalFileName),
                        Extension    = Path.GetExtension(originalName).ToLower(),
                        Size         = new FileInfo(file.LocalFileName).Length
                    };

                    modelList.Add(fileDto);
                }

                if (useCloud)
                {
                    await fileService.SendCloud(modelList, localPath);
                }

                await fileService.Add(modelList, IdentityClaimsValues.UserId <Guid>());

                return(Ok(Messages.Ok));
            }
            catch (Exception exMessage)
            {
                return(Content(HttpStatusCode.InternalServerError, exMessage));
            }
        }