Beispiel #1
0
        public async Task SetTokenAsync(User user, string loginProvider, string name, string value, CancellationToken cancellationToken)
        {
            if (cancellationToken != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (string.IsNullOrWhiteSpace(loginProvider))
            {
                throw new ArgumentNullException(nameof(loginProvider));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            var userToken = new UserToken
            {
                LoginProvider = loginProvider,
                Name          = name,
                Value         = value,
                UserId        = user.Id
            };

            await _userTokenService.AddAsync(userToken);

            return;
        }
Beispiel #2
0
        public async Task AddProjectAsync([FromBody] ExtendedTask item)
        {
            await taskService.AddAsync(item.Task);

            var task = await taskService.GetAsync(el =>
                                                  el.Name == item.Task.Name &&
                                                  el.Description == item.Task.Description &&
                                                  el.DateStart == item.Task.DateStart &&
                                                  el.Status == item.Task.Status);

            ProjectTask tmp = await projectTaskService.GetAsync(el =>
                                                                item.IdUser == el.IdUser &&
                                                                item.IdProject == el.IdProject &&
                                                                task.IdTask == el.IdTask);

            if (tmp == null)
            {
                await projectTaskService.AddAsync(new ProjectTask
                {
                    IdProject = item.IdProject,
                    IdUser    = item.IdUser,
                    DateStart = item.Task.DateStart,
                    IdTask    = task.IdTask
                });
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Save(Appuser appuser)

        {
            var newperson = await _appuserService.AddAsync(appuser);

            return(Ok(newperson));
        }
Beispiel #4
0
        public async Task <IActionResult> Post([FromBody] RoundDto dto)
        {
            var round = _mapper.Map <Round>(dto);
            await _roundService.AddAsync(round);

            return(Created("localhost", ""));
        }
        public async Task <IActionResult> Post([FromBody] PredictionDto dto)
        {
            var prediction = _mapper.Map <Prediction>(dto);
            await _predictionService.AddAsync(prediction);

            return(Created("localhost", ""));
        }
        private async Task Add()
        {
            var viewModel = GetViewModel();
            var group     = _groupMenu.GetFromInput(viewModel);

            await _groupService.AddAsync(group);
        }
        public async Task <IActionResult> Post([FromBody] BranchOfficeDto value)
        {
            if (value == null)
            {
                return(InvalidRequestBodyJson(nameof(BranchOfficeDto)));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!CheckTimeZoneCode(value.TimeZoneId))
            {
                AddErrors(new [] { $"Unknown time zone code specified: {value.TimeZoneId}" });
            }

            var newBranchOffice = Mapper.Map <BranchOffice>(value);

            newBranchOffice.TenantId = _tenantIdProvider.GetTenantId();
            await _branchOfficeService.AddAsync(newBranchOffice);

            return(Created(nameof(GetBranchOffice), new CreatedWithGuidDto {
                Id = newBranchOffice.Id
            }));
        }
Beispiel #8
0
        public async Task AddToRoleAsync(User user, string roleName, CancellationToken cancellationToken)
        {
            if (cancellationToken != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (string.IsNullOrWhiteSpace(roleName))
            {
                throw new ArgumentNullException(nameof(roleName));
            }


            var role = await _roleService.GetSingleAsync(i => i.Name == roleName);

            await _userRoleService.AddAsync(new UserRole()
            {
                UserId = user.Id,
                RoleId = role.Id,
            });

            return;
        }
Beispiel #9
0
        public void AddUser([FromBody] User user)
        {
            var sha256 = new SHA256Managed();

            user.Password = Convert.ToBase64String(sha256.ComputeHash(Encoding.UTF8.GetBytes(user.Password)));
            userService.AddAsync(user);
        }
Beispiel #10
0
        public async Task <JsonResult> AddEducationDetails(EducationDetailsResource educationDetailsResource)
        {
            if (ModelState.IsValid)
            {
                var userid = System.Web.HttpContext.Current.User.Identity.GetUserId();

                var educationdetails = Mapper.Map <EducationDetailsResource, EducationDetails>(educationDetailsResource);
                educationdetails.EducationTypeId   = educationDetailsResource.EducationTypeId;
                educationdetails.InstituteName     = educationDetailsResource.InstituteName;
                educationdetails.YearFromId        = educationDetailsResource.YearFromId;
                educationdetails.CreatedDate       = DateTime.Now;
                educationdetails.UpdatedDate       = DateTime.Now;
                educationdetails.UserId            = userid;
                educationdetails.YearToId          = educationDetailsResource.YearToId;
                educationdetails.ApplicationUserId = userid;
                educationdetails.Status            = true;

                await _EducationDetailsService.AddAsync(educationdetails);

                _EducationDetailsService.UnitOfWorkSaveChanges();
                return(Json("Success"));
            }


            return(Json("Error"));
        }
        public async Task <HttpResponseMessage> Post(FileModel model)
        {
            var userFile = new DomainUserFile
            {
                Created     = DateTime.UtcNow,
                Modified    = DateTime.UtcNow,
                UserId      = UserId,
                FileUri     = model.File.Uri,
                ContentType = model.File.ContentType,
                FileLength  = model.File.Length,
                FileName    = model.Name
            };

            userFile = await _userFileRepository.AddAsync(userFile);

            var file = new File
            {
                ContentType = userFile.ContentType,
                Name        = userFile.FileName,
                Uri         = userFile.FileUri,
                Id          = userFile.FileId,
                Length      = userFile.FileLength
            };

            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, file);

            response.SetLastModifiedDate(userFile.Modified);

            return(response);
        }
        public async Task <IActionResult> Save(Person person)
        {
            // normally we should use dto s but i will be doing that later
            var _person = await _personService.AddAsync(person);

            return(Ok(_person));
        }
Beispiel #13
0
        public virtual async Task <IHttpActionResult> Post(TEntity entity)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var result = await _service.AddAsync(entity, User.Identity.Name?.Split("\\".ToCharArray()).LastOrDefault());

                if (_service.Errors.Any())
                {
                    return(RetrieveErrorResult(_service.Errors));
                }

                var castkey = _service.GetEntityIdObject(entity) as int?;

                // If a logging service has been injected then use it.
                if (_logService != null && castkey != null)
                {
                    //await _logService.InfoAsync(entity, (int)_service.GetEntityIdObject(entity), EventType.Added, loggedInUserName: User?.Identity?.Name, useToString: true);
                }

                return(Created(result));
            }
            catch (Exception ex)
            {
                _logService?.Info(ex);

                return(InternalServerError(ex));
            }
        }
Beispiel #14
0
        public async Task <IActionResult> Post(TeamDto dto)
        {
            var team = _mapper.Map <Team>(dto);
            await _teamService.AddAsync(team);

            return(Created("localhost", ""));
        }
        public async Task <IActionResult> Post([FromBody] ScoreDto dto)
        {
            var score = _mapper.Map <Score>(dto);
            await _scoreService.AddAsync(score);

            return(Created("localhost", ""));
        }
Beispiel #16
0
        public async Task <IActionResult> Save(Person person)

        {
            var newperson = await _personService.AddAsync(person);

            return(Ok(newperson));
        }
        public async Task <IActionResult> Post([FromBody] SportDto dto)
        {
            var sport = _mapper.Map <Sport>(dto);
            await _sportService.AddAsync(sport);

            return(Created("localhost", ""));
        }
        public async Task <ActionResult> AddVaccine(int patientId, [FromBody] VaccineDto vaccine)
        {
            vaccine.PatientId = patientId;
            var res = await vaccineService.AddAsync(vaccine);

            return(Created($"/api/patient/{patientId}/vaccine/{res.Id}", res));
        }
        public async Task <IActionResult> Post([FromBody] MatchDto dto)
        {
            var match = _mapper.Map <Match>(dto);
            await _matchService.AddAsync(match);

            return(Created("localhost", ""));
        }
        public async Task <IActionResult> CommentAddOrEdit([FromForm] CommentViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var orderItem = await _orderItemService.SingleOrDefaultAsync(p => p.Id == model.OrderItemId);

                    model.Rating.ProductId   = orderItem.ProductId;
                    model.Rating.OrderItemId = orderItem.Id;
                    await _orderItemService.AddComment(model.OrderItemId);

                    if (model.Rating.Id == 0)
                    {
                        model.Rating.CreationDate = DateTime.Now;
                        await _ratingService.AddAsync(_mapper.Map <Rating>(model.Rating));
                    }
                    else
                    {
                        model.Rating.DateOfUpdate = DateTime.Now;
                        _ratingService.Update(_mapper.Map <Rating>(model.Rating));
                    }
                    return(Json(new { isValid = true, success = true, message = Messages.JSON_CREATE_MESSAGE("Değerlendirme"), redirectUrl = "/my-orders" }));
                }
                return(Json(new { isValid = false, success = false, message = Messages.JSON_CREATE_MESSAGE("Değerlendirme", false), redirectUrl = "/my-orders" }));
            }
            catch (Exception)
            {
                return(Json(new { isValid = false, success = false, message = Messages.JSON_CREATE_MESSAGE("Değerlendirme", false), redirectUrl = "/my-orders" }));
            }
        }
Beispiel #21
0
        public async Task Add_IfModelWasAlreadyAdded_ShouldThrowException(IService <T> service)
        {
            //var posts = await service.GetAllAsync().SyncResult();
            var postAlreadyAdded = service.GetAllAsync().SyncResult().First();

            await Assert.ThrowsAsync <Exception>(async() => await service.AddAsync(postAlreadyAdded));
        }
Beispiel #22
0
        public void Get_IfAddedModel_ShouldReturnTheAddedOne(IService <T> service, T modelToBeAdded)
        {
            service.AddAsync(modelToBeAdded).Wait();
            var gotModel = service.GetAsync(modelToBeAdded.Id).SyncResult();

            Assert.Equal(modelToBeAdded.Id, gotModel.Id);
        }
Beispiel #23
0
        public void Get_IfAddedModel_ShouldReturnNotNullOne(IService <T> service, T modelToBeAdded)
        {
            service.AddAsync(modelToBeAdded).Wait();
            var gotModel = service.GetAsync(modelToBeAdded.Id).SyncResult();

            Assert.NotNull(gotModel);
        }
Beispiel #24
0
        public async Task <IdentityResult> CreateAsync(Role role, CancellationToken cancellationToken)
        {
            try
            {
                if (cancellationToken != null)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                }

                if (role == null)
                {
                    throw new ArgumentNullException(nameof(role));
                }

                await _roleService.AddAsync(role);

                return(IdentityResult.Success);
            }
            catch (Exception ex)
            {
                return(IdentityResult.Failed(new IdentityError {
                    Code = ex.Message, Description = ex.Message
                }));
            }
        }
Beispiel #25
0
        public async Task AddClaimAsync(Role role, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (cancellationToken != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            if (role == null)
            {
                throw new ArgumentNullException(nameof(role));
            }

            if (claim == null)
            {
                throw new ArgumentNullException(nameof(claim));
            }

            var roleClaimEntity = new RoleClaim
            {
                ClaimType  = claim.Type,
                ClaimValue = claim.Value,
                RoleId     = role.Id
            };

            await _roleClaimService.AddAsync(roleClaimEntity);


            return;
        }
Beispiel #26
0
        public async Task <IActionResult> AddSemester(SemesterModel model)
        {
            try
            {
                var    OperationType = _session.GetString("OperationType");
                var    semester      = new Semester();
                string mesaj         = "";

                //Yeni Kayıt İse ekle
                if (OperationType == Constants.OperationType.Insert)
                {
                    #region Semester Sistemde Var Mı Kontrolü
                    semester = await _semesterService.SingleOrDefaultAsync(x => x.Name == model.Name && x.SemesterType == model.SemesterType && x.IsDeleted == false);

                    if (semester != null)
                    {
                        return(Json(new JsonMessage {
                            HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Eklemek istediğiniz özelliklere sahip semester sistemde zaten mevcut."
                        }));
                    }
                    #endregion

                    #region Semester Ekle
                    semester = new Semester
                    {
                        Name         = model.Name,
                        SemesterType = model.SemesterType,
                        Code         = model.Code,
                        IsDeleted    = false
                    };
                    await _semesterService.AddAsync(semester);

                    mesaj = "Yeni Semester Başarıyle Eklendi.";
                    #endregion
                }
                if (OperationType == Constants.OperationType.Update)
                {
                    #region Update İşlemi
                    semester = await _semesterService.GetByIdAsync(model.Id);

                    semester.Name         = model.Name;
                    semester.SemesterType = model.SemesterType;
                    semester.Code         = model.Code;
                    _semesterService.Update(semester);
                    mesaj = "Yeni Semester Başarıyle Güncellendi.";
                    #endregion
                }

                return(Json(new JsonMessage {
                    HataMi = false, Baslik = "İşlem Başarılı", Mesaj = mesaj
                }));
            }
            catch (Exception ex)
            {
                return(Json(new JsonMessage {
                    HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "İşlem Sırasında Hata Oluştu."
                }));
            }
        }
Beispiel #27
0
        public void Delete_IfAddedModelDeleted_ShouldNotBeFoundByGetAndGetAll(IService <T> service, T modelToBeDeleted)
        {
            service.AddAsync(modelToBeDeleted).Wait();
            service.DeleteAsync(modelToBeDeleted.Id).Wait();

            Assert.Null(service.GetAsync(modelToBeDeleted.Id).SyncResult());
            Assert.DoesNotContain(service.GetAllAsync().SyncResult(), p => p.Id == modelToBeDeleted.Id);
        }
Beispiel #28
0
        public async Task <IActionResult> AddProgram(ProgramModel model)
        {
            try
            {
                var    OperationType = _session.GetString("OperationType");
                var    program       = new Programs();
                string mesaj         = "";

                //Yeni Kayıt İse ekle
                if (OperationType == Constants.OperationType.Insert)
                {
                    #region Program Sistemde Var Mı Kontrolü
                    program = await _programService.SingleOrDefaultAsync(x => x.Name == model.Name || x.Code == model.Code && x.IsDeleted == false);

                    if (program != null)
                    {
                        return(Json(new JsonMessage {
                            HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Eklemek istediğiniz özelliklere sahip program sistemde zaten mevcut."
                        }));
                    }
                    #endregion

                    #region Program Ekle
                    program = new Programs
                    {
                        Name      = model.Name,
                        Code      = model.Code,
                        IsDeleted = false
                    };
                    await _programService.AddAsync(program);

                    mesaj = "Yeni Program Başarıyle Eklendi.";
                    #endregion
                }
                if (OperationType == Constants.OperationType.Update)
                {
                    #region Update İşlemi
                    program = await _programService.GetByIdAsync(model.Id);

                    program.Name = model.Name;
                    program.Code = model.Code;
                    _programService.Update(program);
                    mesaj = "Yeni Program Başarıyle Güncellendi.";
                    #endregion
                }

                return(Json(new JsonMessage {
                    HataMi = false, Baslik = "İşlem Başarılı", Mesaj = mesaj
                }));
            }
            catch (Exception ex)
            {
                return(Json(new JsonMessage {
                    HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "İşlem Sırasında Hata Oluştu."
                }));
            }
        }
        public virtual async Task <TResponseModel> Add(
            [FromBody] TRequestModel requestModel)
        {
            var model = RequestModelMapper.Map(requestModel);

            model = await Service.AddAsync(model);

            return(ResponseModelMapper.Map(model));
        }
Beispiel #30
0
        private async void button1_Click(object sender, EventArgs e)
        {
            var added = await _goodTypeService.AddAsync(new GoodTypeDto()
            {
                Name = textBox1.Text
            });

            MessageBox.Show($"Added {added}");
        }