示例#1
0
        public ActionResult Edit_Order(string id_list)
        {
            ApplicationUser cur_user   = Get_Cur_User();
            List <int>      ids        = new List <int>(); // will hold
            int             id_counter = 1;                // Determines each row number of an item

            ids = id_list.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).
                  Select(int.Parse).ToList();

            // sorts the list based on new row numbers
            foreach (var id in ids)
            {
                try
                {
                    Models.ToDo toDo = db.ToDos.Where(x => x.ID == id).FirstOrDefault();
                    if (toDo.user != cur_user)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                    }
                    toDo.row_number      = id_counter;
                    db.Entry(toDo).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    continue;
                }
                id_counter++;
            }

            return(ToDoList());
        }
示例#2
0
        public async Task <BaseResponseDto <bool> > Handle(CreateToDoRequest request, CancellationToken cancellationToken)
        {
            BaseResponseDto <bool> response = new BaseResponseDto <bool>();

            try
            {
                var toDo = new Models.ToDo
                {
                    Name        = request.Name,
                    IsCompleted = false,
                    CreatedAt   = DateTime.Now
                };

                await repository.CreateAsync(toDo);

                response.Data = true;

                await mediator.Publish(new NewToDoCreatedEvent(toDoName : toDo.Name));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                response.Errors.Add("An error occurred while creating the ToDo.");
            }

            return(response);
        }
示例#3
0
        public async Task <ActionResult <Models.ToDo> > Post([FromBody, Required] Models.ToDo value)
        {
            if (value.Id != 0)
            {
                Response.Headers.Add("x-status-reason", $"ToDo should not have an non positive id '{value.Id}' ");
                return(BadRequest());
            }
            var ToDo = _Mapper.Map <Core.Dal.ToDo>(value);

            _unitOfWork.ToDos.Add(ToDo);

            await _unitOfWork.CommitAsync();

            //var inserted = await _ToDoRepository.Add(ToDo);
            //if (inserted == null || inserted.Id <= 0)
            //{
            //	Response.Headers.Add("x-status-reason", $"ToDo '{value}' is not saved.");
            //	this.BadRequest();
            //}

            //var result = _Mapper.Map<Models.ToDo>(inserted);
            //return this.Ok(result);

            return(CreatedAtAction(nameof(Get), new { id = ToDo.Id }, ToDo));
        }
 public ToDoMaintenanceViewModel( IToDoClient toDoClient, IMetaClient metaClient, Models.ToDo toDo)
 {
     _toDoClient = toDoClient;
     _metaClient = metaClient;
     _toDo = toDo;
     Initialize();
 }
示例#5
0
        public async Task <Models.ToDo> CreateAsync(Models.ToDo toDo)
        {
            var data = Models.ToDo.Create(toDo);

            var result = await dbContext.ToDos.AddAsync(data);

            return(result.Entity);
        }
示例#6
0
        public ToDoPage(IEasyMobileServiceClient client, Models.ToDo todo)
        {
            InitializeComponent();

            var viewModel = new ViewModels.ToDoViewModel(client, todo);

            BindingContext = viewModel;
        }
示例#7
0
 public ToDoDto(Models.ToDo data)
 {
     Id             = data.Id;
     Title          = data.Title;
     Description    = data.Description;
     Position       = data.Position;
     IsCompleted    = data.IsCompleted;
     DateCreatedUtc = data.DateCreatedUtc;
     DateUpdatedUtc = data.DateUpdatedUtc;
 }
示例#8
0
        public void PutTodo(Models.ToDo body)
        {
            var results = _context.ToDo.Where(e => e.Id == body.Id).SingleOrDefault();

            results.IsComplete = results.IsComplete == true ? false : true;
            if (body.Item != results.Item)
            {
                results.Item = body.Item;
            }
            _context.SaveChanges();
        }
示例#9
0
        public void Add(string title, string date, string time, string details)
        {
            var m = new Models.ToDo();

            m.Title   = title;
            m.Details = details;
            m.DueDate = ParseDate(date, time);
            m.ID      = Program.ToDoList.Max(x => x.ID) + 1;

            Program.ToDoList.Add(m);
        }
示例#10
0
        public async Task UpdateAsync(Models.ToDo toDo)
        {
            var data = await dbContext.ToDos
                       .SingleOrDefaultAsync(t => t.Id == toDo.Id);

            if (data == null)
            {
                throw new NotFoundException {
                          Id = toDo.Id
                }
            }
            ;

            data.Update(toDo);
        }
    }
示例#11
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ToDo = await _toDoService.GetByIdAsync(id.Value);

            if (ToDo != null)
            {
                await _toDoService.RemoveAsync(id.Value);
            }

            return(RedirectToPage("./Index"));
        }
示例#12
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ToDo = await _toDoService.GetByIdAsync(id.Value);

            if (ToDo == null)
            {
                return(NotFound());
            }

            return(Page());
        }
示例#13
0
        public async Task <ActionResult <Models.ToDo> > Put(int id, [FromBody, Required] Models.ToDo value)
        {
            if (id != value.Id)
            {
                Response.Headers.Add("x-status-reason", $"ToDo with id '{value.Id}' does not match the id '{id}'.");
                return(BadRequest());
            }
            var ToDo = _Mapper.Map <Core.Dal.ToDo>(value);

            var entity = await _unitOfWork.ToDos.Get(id);

            if (entity == null)
            {
                Response.Headers.Add("x-status-reason", $"ToDo with id '{id}' is not found.");
                return(NotFound());
            }

            entity.Description = value.Description;
            entity.Name        = value.Name;
            entity.Priority    = (int)value.Priority;
            entity.Updated     = DateTime.UtcNow;

            await _unitOfWork.CommitAsync();

            //var updated = await _ToDoRepository.Update(ToDo);
            //if (updated == null || updated.Id <= 0)
            //{
            //	Response.Headers.Add("x-status-reason", $"ToDo '{value}' is not saved.");
            //	this.BadRequest();
            //}

            //var result = _Mapper.Map<Models.ToDo>(updated);
            //return this.Ok(result);

            return(NoContent());
        }
 private void SetID(Models.ToDo td)
 {
     td.ID = _id++;
 }
 public void AddToDo(Models.ToDo td)
 {
     td.CreatedAt = DateTime.Now;
     SetID(td);
     todo.Add(td);
 }
 public IActionResult AddNewElement(Models.ToDo td)
 {
     todoapp.AddToDo(td);
     return(RedirectToAction("Index"));
 }