public async Task AddNewActivity() { //Arrange var activityType = ActivityTypeFactory.Default(); var city = CityFactory.Default(); var activity = new CreateActivityModel() { ActivityTypeId = activityType.Id, Address = "test address", CityId = city.Id, Description = "test description", Name = "test name" }; //Act await ExecuteDatabaseAction(async (doFestContext) => { await doFestContext.ActivityTypes.AddAsync(activityType); await doFestContext.Cities.AddAsync(city); await doFestContext.SaveChangesAsync(); }); //Assert var response = await HttpClient.PostAsJsonAsync($"/api/v1/activities", activity); response.IsSuccessStatusCode.Should().BeTrue(); }
public void Post([FromBody] CreateActivityModel activity) { var entity = Activity.Create(activity.Name, activity.Description, activity.Type, activity.DashboardId, activity.StartingTime, activity.EndingTime); //Activity.AddActivity(entity); _repository.Add(entity); }
public void CreateActivity(CreateActivityModel createActivityModel) { //TODO: Check if there are any links that time and rewire them _context.Set <Activity>().Add(new Activity(createActivityModel.Name, createActivityModel.StartAt, createActivityModel.EndAt, createActivityModel.ActivityType)); }
public async Task <IActionResult> Add([FromBody] CreateActivityModel activity) { var(_, isFailure, result, error) = await _activitiesService.Add(activity); if (isFailure) { return(BadRequest(error)); } return(Created(result.Id.ToString(), result)); }
public IActionResult Post([FromBody] CreateActivityModel model) { var userId = this.GetAuthorizeUserId(); var activityId = _activityRepository.AddActivity(userId, model.Name); var activity = new ActivityModel { Id = activityId, Name = model.Name }; return(Created(string.Format("/api/users/{0}/activities/{1}", userId, activityId), activity)); }
public async Task <Result <ActivityModel, Error> > Add(CreateActivityModel model) { // Check authority var userId = Guid.Parse(_accessor.HttpContext.User.Claims.First(c => c.Type == "userId").Value); var user = await _userRepository.GetById(userId); var userType = await _userTypeRepository.GetByName("Admin"); if (userType.Id != user.UserTypeId) { return(Result.Failure <ActivityModel, Error>(ErrorsList.UnauthorizedUser)); } var isActivityTypeNull = (await _activityTypesRepository.GetById(model.ActivityTypeId)) == null; if (isActivityTypeNull) { return(Result.Failure <ActivityModel, Error>(ErrorsList.UnavailableActivityType)); } var isCityNull = (await _cityRepository.GetById(model.CityId)) == null; if (isCityNull) { return(Result.Failure <ActivityModel, Error>(ErrorsList.InvalidCity)); } var activityModel = await _activitiesRepository.GetByName(model.Name); if (activityModel != null) { return(Result.Failure <ActivityModel, Error>(ErrorsList.ActivityExists)); } var activityEntity = _mapper.Map <Activity>(model); await _activitiesRepository.Add(activityEntity); await _activitiesRepository.SaveChanges(); return(_mapper.Map <ActivityModel>(activityEntity)); }
public ActionResult <ApiResponse <ActivityModel> > CreateActivity([FromBody] CreateActivityModel model) { try { var onlineUser = this._userService.GetOnlineUser(this.HttpContext); if (onlineUser == null) { return(Json(ApiResponse.WithError("Not Authority"))); } var customerLastActivity = this._customerService.GetCustomerLastActivity(model.CustomerId); ActivityModel result = null; var newActivity = new Activity(); newActivity.Description = model.Description; newActivity.CustomerId = model.CustomerId; newActivity.ActivityType = model.ActivityType; newActivity.UserId = model.UserId; newActivity.Amount = model.Amount; if (model.ActivityType == ActivityType.Purchase) { if (customerLastActivity != null) { newActivity.CurrentDept = model.CurrentDept + customerLastActivity.CurrentDept; } else { newActivity.CurrentDept = model.CurrentDept + 0; } } else if (model.ActivityType == ActivityType.Payment) { if (customerLastActivity != null) { newActivity.CurrentDept = customerLastActivity.CurrentDept - model.CurrentDept; } else { newActivity.CurrentDept = model.CurrentDept + 0; } } else if (model.ActivityType == ActivityType.ProductReturns) { if (customerLastActivity != null) { newActivity.CurrentDept = model.CurrentDept - customerLastActivity.CurrentDept; } else { newActivity.CurrentDept = model.CurrentDept + 0; } } this._customerService.AddNewActivity(newActivity); result = this._customerService.GetActivityById(newActivity.Id); return(Json(ApiResponse <ActivityModel> .WithSuccess(result))); } catch (Exception exp) { return(Json(ApiResponse <ActivityModel> .WithError(exp.ToString()))); } }
public static CreateActivityModel WithActivityType(this CreateActivityModel model, Guid activityTypeId) { model.ActivityTypeId = activityTypeId; return(model); }
public static CreateActivityModel WithName(this CreateActivityModel model, string name) { model.Name = name; return(model); }
public static CreateActivityModel WithDescription(this CreateActivityModel model, string description) { model.Description = description; return(model); }
public static CreateActivityModel WithCityId(this CreateActivityModel model, Guid cityId) { model.CityId = cityId; return(model); }
public static CreateActivityModel WithAddress(this CreateActivityModel model, string address) { model.Address = address; return(model); }
public ActionResult Create(CreateActivityModel createActivityModel) { _activityService.CreateActivity(createActivityModel); return(RedirectToAction("Index")); }
public ActionResult <ApiResponse <ActivityModel> > CreateActivity([FromBody] CreateActivityModel model, decimal paymentAmount) { try { var onlineUser = this._userService.GetOnlineUser(this.HttpContext); if (onlineUser == null) { return(Json(ApiResponse <List <ActivityModel> > .WithError("Not authorized !"))); } if (model.UserId != onlineUser.Id) { return(Json(ApiResponse <List <ActivityModel> > .WithError("Not authorized !"))); } paymentAmount = Math.Round(paymentAmount, 2); model.CurrentDebt = Math.Round(model.CurrentDebt, 2); model.Amount = Math.Round(model.Amount, 2); List <ActivityModel> result = new List <ActivityModel>(); if (model.ActivityType == Enum.ActivityType.Payment) { var newActivity = new Activity(); newActivity.Description = model.Description; newActivity.CustomerId = model.CustomerId; newActivity.UserId = model.UserId; newActivity.ActivityType = model.ActivityType; var lastActivity = this._customerService.GetLastActivity(model.CustomerId); var currentDebt = lastActivity.CurrentDebt; if (currentDebt < model.Amount) { newActivity.Amount = currentDebt; newActivity.CurrentDebt = 0; } else { newActivity.Amount = model.Amount; newActivity.CurrentDebt = currentDebt - model.Amount; } this._customerService.AddNewActivity(newActivity); result.Add(this._customerService.GetActivityById(newActivity.Id)); return(Json(ApiResponse <List <ActivityModel> > .WithSuccess(result))); } if (model.ActivityType == Enum.ActivityType.Purchase && paymentAmount > 0) { var newActivity = new Activity(); newActivity.UserId = model.UserId; newActivity.Description = model.Description; newActivity.CustomerId = model.CustomerId; newActivity.Amount = model.Amount; newActivity.ActivityType = model.ActivityType; newActivity.CurrentDebt = model.Amount; this._customerService.AddNewActivity(newActivity); var paymentActivity = new Activity(); paymentActivity.Description = model.Description; paymentActivity.UserId = onlineUser.Id; paymentActivity.CustomerId = model.CustomerId; paymentActivity.Amount = paymentAmount; paymentActivity.ActivityType = Enum.ActivityType.Payment; var lastActivity = this._customerService.GetLastActivity(model.CustomerId); var currentDebt = lastActivity.CurrentDebt - paymentAmount; paymentActivity.CurrentDebt = currentDebt; this._customerService.AddNewActivity(paymentActivity); result.Add(newActivity.ToModel()); result.Add(paymentActivity.ToModel()); return(Json(ApiResponse <List <ActivityModel> > .WithSuccess(result))); } if ((model.ActivityType == Enum.ActivityType.Purchase) && paymentAmount <= 0) { var newActivity = new Activity(); newActivity.UserId = model.UserId; newActivity.Description = model.Description; newActivity.CustomerId = model.CustomerId; newActivity.Amount = model.Amount; newActivity.ActivityType = model.ActivityType; newActivity.CurrentDebt = model.Amount; this._customerService.AddNewActivity(newActivity); result.Add(this._customerService.GetActivityById(newActivity.Id)); return(Json(ApiResponse <List <ActivityModel> > .WithSuccess(result))); } if (model.ActivityType == Enum.ActivityType.ProductReturn) { var newActivity = new Activity(); newActivity.UserId = model.UserId; newActivity.Description = model.Description; newActivity.CustomerId = model.CustomerId; newActivity.Amount = model.Amount; newActivity.ActivityType = model.ActivityType; var currentDebt = this._customerService.GetLastActivity(model.CustomerId).CurrentDebt; newActivity.CurrentDebt = currentDebt; this._customerService.AddNewActivity(newActivity); result.Add(this._customerService.GetActivityById(newActivity.Id)); var paymentActivity = new Activity(); paymentActivity.Description = model.Description; paymentActivity.UserId = onlineUser.Id; paymentActivity.CustomerId = model.CustomerId; if (model.CurrentDebt <= paymentAmount) { paymentActivity.Amount = paymentAmount - (paymentAmount - currentDebt); paymentActivity.CurrentDebt = 0; } else { paymentActivity.Amount = 0; paymentActivity.CurrentDebt = currentDebt - paymentAmount; } paymentActivity.ActivityType = Enum.ActivityType.PaymentReturn; this._customerService.AddNewActivity(paymentActivity); result.Add(this._customerService.GetActivityById(paymentActivity.Id)); return(Json(ApiResponse <List <ActivityModel> > .WithSuccess(result))); } return(Json(ApiResponse <ActivityModel> .WithError("FONKSIYON BULUNAMADI"))); } catch (Exception exp) { return(Json(ApiResponse <ActivityModel> .WithError(exp.ToString()))); } }
public ActionResult Create(CreateActivityModel createActivityModel) { _bus.Send(createActivityModel); return(RedirectToAction("Index")); }