Ejemplo n.º 1
0
        public static object DeleteReception(int Id)
        {
            try
            {
                //using context and LINQ
                using (var ctx = new HospitalDatabaseEntities())
                {
                    //Выглядит странно, но это так и делается
                    Reception deleteThis = new Reception()
                    {
                        Id = Id
                    };
                    ctx.Reception.Attach(deleteThis);
                    ctx.Reception.Remove(deleteThis);

                    ctx.SaveChanges(); //Иначе ничего не сохраняет в БД из контекста
                }

                return(new { Result = "OK" });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Ejemplo n.º 2
0
        public static object UpdateReception(Reception record)
        {
            try
            {
                //using context and LINQ
                using (var ctx = new HospitalDatabaseEntities())
                {
                    var foundReception = ctx.Reception.FirstOrDefault(s => s.Id == record.Id);
                    if (foundReception == null)
                    {
                        throw new Exception("Запись не найдена!");
                    }

                    foundReception.Doctor_Id  = record.Doctor_Id;
                    foundReception.Patient_Id = record.Patient_Id;
                    foundReception.Date       = record.Date;

                    ctx.SaveChanges(); //Иначе ничего не сохраняет в БД из контекста
                }

                return(new { Result = "OK" });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Ejemplo n.º 3
0
        public static object CreateReception(Reception record)
        {
            try
            {
                //using context and LINQ
                using (var ctx = new HospitalDatabaseEntities())
                {
                    ctx.Reception.Add(record);
                    ctx.SaveChanges(); //Иначе ничего не сохраняет в БД из контекста
                }

                return(new { Result = "OK", Record = record });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }