Ejemplo n.º 1
0
        public Client SaveClient(Client client)
        {
            var cl = new Client();

            using (var context = new VisitsDatabaseEntities())
            {
                var cc = context.Clients.FirstOrDefault(x => x.Document == client.Document && x.DocumentType == client.DocumentType);

                if (cc == null)
                {
                    var c = new Client();
                    c              = new Client();
                    c.Document     = client.Document;
                    c.DocumentType = client.DocumentType;
                    c.ClientName   = client.ClientName;
                    c.ContactName  = client.ContactName;
                    c.Email        = client.Email;
                    c.Phone        = client.Phone;
                    c.Address      = client.Address;
                    c.Position     = client.Position;
                    c.Consumption  = client.Consumption;
                    c.Fabric       = client.Fabric;

                    context.Clients.Add(c);

                    context.SaveChanges();

                    cl = c;
                }
                else
                {
                    cc.ClientName  = client.ClientName;
                    cc.ContactName = client.ContactName;
                    cc.Email       = client.Email;
                    cc.Phone       = client.Phone;
                    cc.Address     = client.Address;
                    cc.Position    = client.Position;
                    cc.Consumption = client.Consumption;
                    cc.Fabric      = client.Fabric;

                    context.SaveChanges();

                    cl = cc;
                }
            }

            return(cl);
        }
Ejemplo n.º 2
0
        public int SaveVisit(Visit saveVisit)
        {
            int id = 0;

            using (var context = new VisitsDatabaseEntities())
            {
                var visit = new Visit();

                visit              = new Visit();
                visit.ClientID     = saveVisit.ClientID;
                visit.SellerID     = saveVisit.SellerID;
                visit.Observations = saveVisit.Observations;
                visit.VistDate     = saveVisit.VistDate;

                context.Visits.Add(visit);
                context.SaveChanges();

                id = visit.VisitsID;
            }
            return(id);
        }