Beispiel #1
0
        public medicine edit(medicine acc)
        {
            try
            {
                var entry = _context.Entry <medicine>(acc);

                if (entry.State == System.Data.Entity.EntityState.Detached)
                {
                    var      set            = _context.Set <medicine>();
                    medicine attachedEntity = set.Local.SingleOrDefault(e => e.id == acc.id);  // You need to have access to key

                    if (attachedEntity != null)
                    {
                        var attachedEntry = _context.Entry(attachedEntity);
                        attachedEntry.CurrentValues.SetValues(acc);
                    }
                    else
                    {
                        entry.State = System.Data.Entity.EntityState.Modified; // This should attach entity
                    }
                }
                Logger.Log(acc.commercialName + " is Edited", LogType.Info);
            }
            catch (Exception e)
            {
                Logger.Log(e.ToString(), LogType.Error);
            }
            return(acc);
        }
Beispiel #2
0
        public medicine get(Guid?id)
        {
            if (id == null)
            {
                id = Guid.Empty;
            }
            medicine acc = _context.medicines.FirstOrDefault(o => o.id == (id));

            return(acc);
        }
Beispiel #3
0
 public medicine delete(medicine acc)
 {
     try
     {
         _context.Entry(acc).State = System.Data.Entity.EntityState.Deleted;
         _context.SaveChanges();
         Logger.Log(acc.commercialName + " is Deleted", LogType.Info);
     }
     catch (Exception e)
     {
         Logger.Log(e.ToString(), LogType.Error);
     }
     return(acc);
 }
Beispiel #4
0
 public medicine add(medicine acc)
 {
     try
     {
         _context.medicines.Add(acc);
         _context.SaveChanges();
         Logger.Log(acc.commercialName + " is Added", LogType.Info);
     }
     catch (Exception e)
     {
         Logger.Log(e.ToString(), LogType.Error);
     }
     return(acc);
 }
Beispiel #5
0
        public medicine getByName(string name)
        {
            medicine acc = _context.medicines.FirstOrDefault(o => o.commercialName == name);

            return(acc);
        }