예제 #1
0
        public void add()
        {
            var          childJson = HttpContext.Current.Request.Params["child"];
            var          child     = JsonConvert.DeserializeObject(childJson);
            CChildParent c         = JsonConvert.DeserializeObject <CChildParent>(childJson);

            // CChildParent child = (CChildParent)ser.DeserializeObject(childJson);
            if (HttpContext.Current.Request.Files.AllKeys.Any())
            {
                var file = HttpContext.Current.Request.Files["file"];
                ;
                byte[] data;
                using (Stream inputStream = file.InputStream)
                {
                    MemoryStream memoryStream = inputStream as MemoryStream;
                    if (memoryStream == null)
                    {
                        memoryStream = new MemoryStream();
                        inputStream.CopyTo(memoryStream);
                    }
                    data      = memoryStream.ToArray();
                    c.picture = data;
                }
            }

            BChildrenManager.addChildren(c);
        }
예제 #2
0
        //public static int addChildren(CChildren cc)
        //{
        //    Children c = Mapper.convertToChildren(cc);
        //    using (NDBEntities db = new NDBEntities())
        //    {
        //        try
        //        {
        //            db.Children.Add(c);
        //            db.SaveChanges();
        //            return 1;
        //        }
        //        catch (Exception e)
        //        {

        //            throw;
        //        }
        //    }
        //}

        public static int addChildren(CChildParent cc)
        {
            CUsers    u  = new CUsers(cc.ParentId, cc.ParentFirstName, cc.ParentLastName, cc.Address, cc.Phone, 1, cc.mailAddress, cc.Active);
            Users     u1 = Mapper.convertToUsers(u);
            CChildren c  = new CChildren(cc.ChildId, cc.ChildFirstName, cc.ChildLastName, cc.Address, cc.Phone, cc.ParentCode, cc.KinderGardenCode, cc.Active, cc.picture);
            Children  c1 = Mapper.convertToChildren(c);

            using (NDBEntities db = new NDBEntities())
            {
                try
                {
                    var idParent = (from x in db.Users
                                    where u1.IdUser == x.IdUser
                                    select x.IdUser).FirstOrDefault();
                    if (idParent == null)
                    {
                        db.Users.Add(u1);
                    }
                    Children child = (from x in db.Children
                                      where x.IdChild.Equals(cc.ChildId) && x.Active == 0
                                      select x).FirstOrDefault();
                    if (child != null)
                    {
                        Children ch = db.Children.First(d => d.IdChild.Equals(child.IdChild));
                        ch.Active = 1;
                    }
                    else
                    {
                        db.Children.Add(c1);
                        db.SaveChanges();
                    }

                    return(1);
                }
                catch (Exception e)
                {
                    throw;
                }
            }
        }
예제 #3
0
 public static int addChildren(CChildParent cc)
 {
     return(DChildrenManager.addChildren(cc));
 }