Example #1
0
        public async Task <IActionResult> CreateAsync([FromBody] NewActivity newActivity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var successful = await _activityService.AddActivityAsync(newActivity);

            if (!successful)
            {
                return(BadRequest(new { error = "Could not add item." }));
            }

            return(Ok(successful));
        }
Example #2
0
        public async Task <ActionResult> Add(Activity model, string submit)
        {
            if (model != null)
            {
                if (submit == "Thêm")
                {
                    isAddNew = true;
                    var activity = new Activity
                    {
                        Title          = model.Title,
                        StartDate      = model.StartDate,
                        EndDate        = model.EndDate,
                        Address        = model.Address,
                        ActivityType   = model.ActivityType,
                        Description    = model.Description,
                        ActivityStatus = (int)ActivityStatus.Ready,
                        FilePath       = model.FilePath
                    };
                    await _activityService.AddActivityAsync(activity);

                    SetAlert("Thêm thông tin thành công!", "success");

                    return(RedirectToAction("Index"));
                }
                else if (submit == "Cập Nhật")
                {
                    isAddNew = false;

                    var activityById = await _activityService.GetActivityByIdAsync(model.ID);

                    activityById.StartDate    = model.StartDate;
                    activityById.Title        = model.Title;
                    activityById.ActivityType = model.ActivityType;
                    activityById.Description  = model.Description;
                    activityById.EndDate      = model.EndDate;
                    activityById.Address      = model.Address;
                    activityById.FilePath     = model.FilePath;

                    await _activityService.UpdateActivityAsync(activityById);

                    SetAlert("Cập nhật thông tin thành công!", "success");
                    return(RedirectToAction("Index"));
                }
            }

            return(RedirectToAction("Index"));
        }