Пример #1
0
        public ActionResult HandleChanges(StoreDataHandler handler)
        {
            List <Citizen> citizens     = handler.ObjectData <Citizen>();
            string         errorMessage = null;

            if (handler.Action == StoreAction.Create)
            {
                try
                {
                    foreach (Citizen created in citizens)
                    {
                        repo.Create(created);
                    }
                }catch (Exception e)
                {
                    errorMessage = e.Message;
                }
            }
            else if (handler.Action == StoreAction.Destroy)
            {
                foreach (Citizen deleted in citizens)
                {
                    repo.Delete(deleted.Id);
                    //citizen citizen = await db.citizens.FirstOrDefaultAsync(c => c.id == deleted.id);
                    //db.citizens.Remove(citizen);
                    //await db.SaveChangesAsync();
                }
            }
            else if (handler.Action == StoreAction.Update)
            {
                foreach (Citizen updated in citizens)
                {
                    try
                    {
                        repo.Update(updated);
                    }
                    catch (Exception e)
                    {
                        errorMessage = e.Message;
                    }
                    //citizen citizen = await db.citizens.FirstOrDefaultAsync(c => c.id == updated.id);
                    //CitizenHelper.CitizenUpdate(citizen, updated);
                    //await db.SaveChangesAsync();
                }
            }

            if (errorMessage != null)
            {
                return(this.Store(errorMessage));
            }

            return(handler.Action != StoreAction.Destroy ? (ActionResult)this.Store(citizens) : (ActionResult)this.Content(""));
        }
Пример #2
0
 public void Delete(long id)
 {
     _citizenRepository.Delete(id);
 }