示例#1
0
        public static bool claimRewardByDonor(int rewardId, int donorId)
        {
            dataContext = new RobaSegonaMaEntities();

            Reward r = dataContext.Rewards.Where(x => x.Id == rewardId).FirstOrDefault();
            Donor  d = dataContext.Donors.Where(x => x.Id == donorId).FirstOrDefault();

            if (r.neededPoints > d.points)
            {
                return(false);
            }
            try
            {
                if (r.Donors == null)
                {
                    r.Donors = new List <Donor>();
                }
                r.Donors.Add(d);
                d.Rewards.Add(r);
                d.points -= r.neededPoints;
                dataContext.SaveChanges();
                return(true);
            }

            catch (Exception e)
            {
                return(false);
            }
        }
示例#2
0
        public static Order insertOrder(Order o)
        {
            dataContext = new RobaSegonaMaEntities();
            try
            {
                dataContext.Orders.Add(o);
                dataContext.SaveChanges();

                Cloth c = dataContext.Clothes.Where(x => x.Id == o.Clothes_Id && x.active == true).FirstOrDefault();
                c.active = false;

                Requestor r = dataContext.Requestors.FirstOrDefault(x => x.Id == o.Requestor_Id);

                r.points += c.Classification.value;

                dataContext.SaveChanges();

                return(o);
            }
            catch (Exception e)
            {
                return(null);
            }
            dataContext = new RobaSegonaMaEntities();
        }
        public static List <Cloth> GetAllClothes()
        {
            RobaSegonaMaEntities dc = new RobaSegonaMaEntities();

            List <Cloth> lc = dc.Clothes.ToList();

            return(lc);
        }
        public static Cloth getCloth(int id)
        {
            RobaSegonaMaEntities dc = new RobaSegonaMaEntities();

            Cloth c = dc.Clothes.Where(x => x.Id == id).FirstOrDefault();

            return(c);
        }
        public static Donor GetDonor(int donorID)
        {
            //  dataContext = new RobaSegonaMaEntities(false);
            dataContext = new RobaSegonaMaEntities(false);
            Donor c = dataContext.Donors.Where(x => x.Id == donorID).SingleOrDefault();

            return(c);
        }
示例#6
0
        public static Requestor GetRequestor(int requestorID)
        {
            dataContext = new RobaSegonaMaEntities(false);
            Requestor c = dataContext.Requestors.Where(x => x.Id == requestorID).SingleOrDefault();

            c.MaxClaim = dataContext.MaxClaims.Where(x => x.Id == c.MaxClaims_Id).FirstOrDefault();

            return(c);
        }
示例#7
0
        public static bool CanLogin(Requestor a)
        {
            dataContext = new RobaSegonaMaEntities();
            List <Requestor> lc = GetAllRequestors();

            Requestor requestor = lc.Where(x => x.password == a.password && x.email == a.email).FirstOrDefault();

            if (requestor != null)
            {
                return(true);
            }
            return(false);
        }
        public static Cloth deleteCloth(int id)
        {
            Cloth c;

            c = dc.Clothes.Where(x => x.Id == id).FirstOrDefault();
            if (c != null)
            {
            }
            {
                dc.Clothes.Remove(c);
                dc.SaveChanges();
                dc = new RobaSegonaMaEntities();
            }
            return(new Cloth());;
        }
        public static Cloth updateCloth(int id, Cloth c)
        {
            try
            {
                Cloth c2 = dc.Clothes.Where(x => x.Id == id).SingleOrDefault();


                if (c.active != null)
                {
                    c2.active = c.active;
                }

                if (c.Color != null)
                {
                    c2.Color = c.Color;
                }
                if (c.Gender != null)
                {
                    c2.Gender = c.Gender;
                }
                if (c.Size != null)
                {
                    c2.Size = c.Size;
                }
                if (c.Classification != null)
                {
                    c2.Classification = c.Classification;
                }
                if (c.Warehouse != null)
                {
                    c2.Warehouse = c.Warehouse;
                }
                if (c.dateCreated != null)
                {
                    c2.dateCreated = c.dateCreated;
                }

                dc.SaveChanges();

                return(c2);
            }
            catch (Exception ex)
            {
                return(null);
            }
            dc = new RobaSegonaMaEntities();
        }
        public static Cloth insertCloth(Cloth c)
        {
            try
            {
                dc.Clothes.Add(c);

                dc.SaveChanges();

                dc = new RobaSegonaMaEntities();

                return(c);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        public static bool insertClothList(List <Cloth> list)
        {
            try
            {
                foreach (Cloth item in list)
                {
                    item.dateCreated = DateTime.Now;
                    //item.Id = null;
                }

                dc.Clothes.AddRange(list);
                dc.SaveChanges();
                dc = new RobaSegonaMaEntities();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#12
0
        public static Requestor UpdateRequestorPassword(int id, Requestor c)
        {
            try
            {
                dataContext = new RobaSegonaMaEntities();
                Requestor c0 = dataContext.Requestors.Where(x => x.Id == id).SingleOrDefault();

                if (c.password != null)
                {
                    c0.password = c.password;
                }


                dataContext.SaveChanges();
                return(GetRequestor(id));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        public static Donor InsertDonor(Donor c)
        {
            try
            {
                if (c.ammountGiven == null)
                {
                    c.ammountGiven = 0;
                }

                if (c.points == null)
                {
                    c.points = 0;
                }
                dataContext.Donors.Add(c);
                dataContext.SaveChanges();
                dataContext = new RobaSegonaMaEntities(false);
                return(GetDonor(c.Id));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        public static Donor DeleteDonor(String id)
        {
            Donor c;

            if (Utils.validInt(id))
            {
                int idInt = int.Parse(id);
                c = dataContext.Donors.Where(x => x.Id == idInt || x.dni.Equals(id)).SingleOrDefault();
            }
            else
            {
                c = dataContext.Donors.Where(x => x.dni.Equals(id)).SingleOrDefault();
            }

            if (c != null)
            {
                dataContext.Donors.Remove(c);
                dataContext.SaveChanges();
                dataContext = new RobaSegonaMaEntities(false);
            }

            return(new Donor());
        }
        public static string CanLoginBoth(Donor a)
        {
            dataContext = new RobaSegonaMaEntities(false);
            List <Donor> lc    = GetAllDonors();
            Donor        donor = lc.Where(x => x.password == a.password && x.email == a.email && x.active == true).FirstOrDefault();

            List <Requestor> lr = RequestorRepository.GetAllRequestors();
            // Requestor requestor = lr.Where(x => x.password == a.password && x.email == a.email && x.active == true && x.Status.status1.ToLower().Equals("activated")).FirstOrDefault();
            Requestor requestor = lr.Where(x => x.password == a.password && x.email == a.email && x.active == true && x.Status_Id == 2).FirstOrDefault();

            if (donor != null || requestor != null)
            {
                if (donor != null)
                {
                    return("true-" + "Donor-" + donor.Id);
                }
                else
                {
                    return("true-" + "Requestor-" + requestor.Id);
                }
            }
            return("false");
        }
示例#16
0
        public static List <Reward> getAvailableRewardsDonor(int donorId)
        {
            dataContext = new RobaSegonaMaEntities();

            List <Reward> lc = dataContext.Rewards.ToList();
            List <Reward> lr = new List <Reward>();

            foreach (Reward reward in lc)
            {
                if (reward.Donors == null)
                {
                    lr.Add(reward);
                    continue;
                }
                Donor d = reward.Donors.Where(x => x.Id == donorId).FirstOrDefault();
                if (d == null)
                {
                    lr.Add(reward);
                }
            }


            return(lr);
        }
示例#17
0
        public static Requestor UpdateRequestor(int id, Requestor c)
        {
            try
            {
                dataContext = new RobaSegonaMaEntities();
                Requestor c0 = dataContext.Requestors.Where(x => x.Id == id).SingleOrDefault();
                if (c.name != null)
                {
                    c0.name = c.name;
                }
                if (c.lastName != null)
                {
                    c0.lastName = c.lastName;
                }
                if (c.birthDate != null)
                {
                    c0.birthDate = c.birthDate;
                }
                if (c.gender != null)
                {
                    c0.gender = c.gender;
                }
                if (c.password != null)
                {
                    c0.password = c.password;
                }
                if (c.email != null)
                {
                    c0.email = c.email;
                }
                if (c.securityAnswer != null)
                {
                    c0.securityAnswer = c.securityAnswer;
                }
                if (c.securityQuestion != null)
                {
                    c0.securityQuestion = c.securityQuestion;
                }
                if (c.dateCreated != null)
                {
                    c0.dateCreated = c.dateCreated;
                }
                if (c.active != null)
                {
                    c0.active = c.active;
                }
                if (c.picturePath != null)
                {
                    c0.picturePath = c.picturePath;
                }
                if (c.Language_Id != null)
                {
                    c0.Language_Id = c.Language_Id;
                }
                if (c.dni != null)
                {
                    c0.dni = c.dni;
                }
                if (c.Status_Id != null)
                {
                    c0.Status_Id = c.Status_Id;
                }

                dataContext.SaveChanges();
                return(GetRequestor(id));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        public static Donor UpdateDonor(int id, Donor c)
        {
            try
            {
                Donor c0 = dataContext.Donors.Where(x => x.Id == id).SingleOrDefault();
                if (c.name != null)
                {
                    c0.name = c.name;
                }
                if (c.lastName != null)
                {
                    c0.lastName = c.lastName;
                }
                if (c.birthDate != null)
                {
                    c0.birthDate = c.birthDate;
                }
                if (c.gender != null)
                {
                    c0.gender = c.gender;
                }
                if (c.password != null)
                {
                    c0.password = c.password;
                }
                if (c.email != null)
                {
                    c0.email = c.email;
                }
                if (c.securityAnswer != null)
                {
                    c0.securityAnswer = c.securityAnswer;
                }
                if (c.securityQuestion != null)
                {
                    c0.securityQuestion = c.securityQuestion;
                }
                if (c.dateCreated != null)
                {
                    c0.dateCreated = c.dateCreated;
                }
                if (c.active != null)
                {
                    c0.active = c.active;
                }
                if (c.picturePath != null)
                {
                    c0.picturePath = c.picturePath;
                }
                if (c.ammountGiven != null)
                {
                    c0.ammountGiven = c.ammountGiven;
                }
                if (c.Language != null)
                {
                    c0.Language = c.Language;
                }
                if (c.dni != null)
                {
                    c0.dni = c.dni;
                }
                if (c.points != null)
                {
                    c0.points = c.points;
                }



                dataContext.SaveChanges();
                Donor newDonor = GetDonor(id);
                dataContext = new RobaSegonaMaEntities(false);
                return(newDonor);
            }
            catch (Exception e)
            {
                return(null);
            }
        }