예제 #1
0
        public async Task <IActionResult> Photo(IFormFile File)
        {
            var UploadingStatus = LocalStorage.UploadProfilePhoto(File, Environment.WebRootPath);

            if (!UploadingStatus.Succes)
            {
                return(Error(UploadingStatus.Message));
            }

            AuthenticatedUser = await GetAuthenticatedUserFromDatabaseAsync().ConfigureAwait(false);

            string oldPhotoPath = AuthenticatedUser.PictureUrl;

            AuthenticatedUser.PictureUrl    = UploadingStatus.UploadedPathAfterRoot;
            AuthenticatedUser.LastChangedOn = DateTime.Now;

            var result = await Context.SaveChangesAsync();

            if (result > 0)
            {
                await SignInWithCookie(AuthenticatedUser);

                if (oldPhotoPath != null)
                {
                    LocalStorage.DeleteIfExists(Environment.WebRootPath + oldPhotoPath);
                }

                return(Succes(null, new { photo = UploadingStatus.UploadedPathAfterRoot }, 201));
            }
            else
            {
                LocalStorage.DeleteIfExists(Environment.WebRootPath + UploadingStatus.UploadedPathAfterRoot);
                return(Error(null, null, null, 1001));
            }
        }
예제 #2
0
        public async Task <IActionResult> PatchRemove(Guid Id)
        {
            var AuthenticatedUserId = User.Identity.GetUserId();

            if (Id == Guid.Empty)
            {
                return(Error("Silinmesi gereken eğitim bilgisine ulaşılamadı"));
            }

            var deletedEducation = await Context.UserEducation.FirstOrDefaultAsync(x => x.Id == Id && !x.IsRemoved && Guid.Parse(AuthenticatedUserId) == x.UserId);

            if (deletedEducation != null)
            {
                if (await IsCanRemovable(deletedEducation))
                {
                    deletedEducation.IsRemoved = true;
                    await Context.SaveChangesAsync();

                    if (deletedEducation.IsSentToConfirmation)
                    {
                        var educationDocuments = await Context.UserEducationDoc.Where(x => x.UserEducationId == deletedEducation.Id).ToListAsync();

                        foreach (var item in educationDocuments)
                        {
                            if (LocalStorage.DeleteIfExists(item.FullPath))
                            {
                                Context.Remove(item);
                            }
                        }
                        await Context.SaveChangesAsync();
                    }
                    return(Succes("Eğitim bilgisi kaldırıldı"));
                }
                else
                {
                    TempData["ProfileMessage"] = "İhtiyaç kampanyanız olduğu için" +
                                                 "<br />" +
                                                 "Aktif olan eğitim bilginizi silemezsiniz." +
                                                 "<br />" +
                                                 "Aktif olan eğitim bilgisi, belge yollayarak hala burada okuduğunuzu iddia ettiğiniz bir eğitim bilgisidir." +
                                                 "<br/>" +
                                                 "Daha fazla ayrıntı ve işlem için: [email protected]";

                    return(Error("Bu eğitimi silemezsiniz"));
                }
            }

            return(Error("Böyle bir eğitiminiz yok", null, null, 404));
        }
예제 #3
0
        [HttpPost("")] //api/me/educationdocuments
        public async Task <IActionResult> Post(Guid Id, IFormFile File)
        {
            var UploadingStatus = LocalStorage.UploadEducationDocument(File, Environment.WebRootPath);

            if (!UploadingStatus.Succes)
            {
                return(Error(UploadingStatus.Message));
            }

            var AuthenticatedUserId = Guid.Parse(User.Identity.GetUserId());

            var Education = await Context.UserEducation.FirstOrDefaultAsync(
                x => x.Id == Id &&
                x.UserId == AuthenticatedUserId &&
                !x.IsRemoved &&
                !x.IsSentToConfirmation);

            if (Education != null)
            {
                var EducationDocument = new UserEducationDoc
                {
                    UserEducationId = Id,
                    FullPath        = Environment.WebRootPath + UploadingStatus.UploadedPathAfterRoot,
                    PathAfterRoot   = UploadingStatus.UploadedPathAfterRoot,
                };

                Education.IsSentToConfirmation = true;
                await Context.AddAsync(EducationDocument);

                var result = await Context.SaveChangesAsync();

                if (result > 0)
                {
                    TempData["ProfileMessage"] = "Eğitim dökümanınız yollandı, en geç 48 saat içinde geri dönüş yapılacak";
                    return(Succes("Eğitim dökümanınız yollandı", null, 201));
                }
                else
                {
                    LocalStorage.DeleteIfExists(EducationDocument.FullPath);
                    return(Error(null, null, null, 1001));
                }
            }

            return(Error("Eğitim bilgisine ulaşılamadı", null, null, 404));
        }