public HttpResponseMessage DeleteUserInfo(string username)
        {
            ConsumerTable CT = db.ConsumerTables.Find(username);

            if (CT == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotAcceptable));
                //return NotFound();
            }
            else
            {
                var ad = (from admin in db.Admins
                          where admin.UserName == CT.UserName
                          select admin).ToList().FirstOrDefault();
                try
                {
                    db.Admins.Remove(ad);
                    db.Admins.Remove(ad);
                    db.ConsumerTables.Remove(CT);
                    db.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK, "UserInfo Deleted"));
                }
                catch (Exception)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, "You cannot delete Active user"));
                }
            }
        }
Ejemplo n.º 2
0
 private void BtnAdd_Click(object sender, RoutedEventArgs e)
 {
     if (Validate(textBoxName) && Validate(textBoxConsumption))
     {
         double result = 0;
         bool   uspelo = false;
         uspelo = double.TryParse(textBoxConsumption.Text, out result);
         if (uspelo && result >= 0)
         {
             ConsumerViewModel.consumers.Add(new ConsumerModel(textBoxName.Text, Double.Parse(textBoxConsumption.Text)));
             using (dbSHESEntities entity = new dbSHESEntities())
             {
                 ConsumerTable cmt = new ConsumerTable()
                 {
                     Name        = textBoxName.Text,
                     Consumption = Double.Parse(textBoxConsumption.Text),
                     State       = Enums.ConsumerEnum.OFF.ToString()
                 };
                 entity.ConsumerTables.Add(cmt);
                 entity.SaveChanges();
             }
         }
         else
         {
             MessageBox.Show("Incorrect input", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else
     {
         MessageBox.Show("Incorrect input", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Ejemplo n.º 3
0
 public void Execute()
 {
     ConsumerViewModel.consumers.Remove(consumerToDelete);
     using (dbSHESEntities entity = new dbSHESEntities())
     {
         ConsumerTable cmt = entity.ConsumerTables.Where(x => x.Name == consumerToDelete.Name).SingleOrDefault();
         if (cmt != null)
         {
             entity.ConsumerTables.Remove(cmt);
             entity.SaveChanges();
         }
     };
 }
 public HttpResponseMessage updateuserinfo(string username, ConsumerTable consumer)
 {
     try
     {
         var userdata = (from con in db.ConsumerTables
                         where con.UserName == username
                         select con).FirstOrDefault();
         userdata.Name    = consumer.Name;
         userdata.PhoneNo = consumer.PhoneNo;
         userdata.Email   = consumer.Email;
         userdata.Address = consumer.Address;
         db.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK, "Record Updated"));
     }
     catch (Exception)
     {
         return(Request.CreateResponse(HttpStatusCode.OK, "Phone Number & Email should be Unique for Particular user"));
     }
 }
        public HttpResponseMessage updateuserinfo(string username, ConsumerTable consumer)
        {
            var userdata = (from con in db.ConsumerTables
                            where con.UserName == username
                            select con).FirstOrDefault();

            userdata.UserName      = consumer.UserName;
            userdata.Name          = consumer.UserName;
            userdata.PhoneNo       = consumer.PhoneNo;
            userdata.Email         = consumer.Email;
            userdata.Address       = consumer.Address;
            userdata.Password      = consumer.Password;
            userdata.CardType      = consumer.CardType;
            userdata.SelectBank    = consumer.SelectBank;
            userdata.IFSC_Code     = consumer.IFSC_Code;
            userdata.AccountNumber = consumer.AccountNumber;
            db.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
 public HttpResponseMessage verifylogin(ConsumerTable logininfo)
 {
     try
     {
         var pas = (from consumer in db.ConsumerTables
                    where consumer.UserName == logininfo.UserName
                    select consumer.Password).FirstOrDefault();
         System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
         System.Text.Decoder      decoder = encoder.GetDecoder();
         byte[] todecode_byte             = Convert.FromBase64String(pas);
         int    charCount    = decoder.GetCharCount(todecode_byte, 0, todecode_byte.Length);
         char[] decoded_char = new char[charCount];
         decoder.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
         string pass = new String(decoded_char);
         var    user = (from consumer in db.ConsumerTables
                        where consumer.UserName == logininfo.UserName && pass == logininfo.Password
                        select consumer.UserName).FirstOrDefault();
         var act = (from ad in db.Admins
                    where ad.UserName == logininfo.UserName
                    select ad.ActivationStatus).FirstOrDefault();
         if (act == false)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, "Not Activated by Admin"));
         }
         else if (user != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, user));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, "Invalid"));
         }
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.OK, e.Message));
     }
 }
Ejemplo n.º 7
0
 public IHttpActionResult PostRegister(ConsumerTable consumertable)
 {
     //if (!ModelState.IsValid)
     //{
     //    return BadRequest(ModelState);
     //}
     //else
     if (consumertable != null)
     {
         db.ConsumerTables.Add(consumertable);
         try {
             db.SaveChanges();
             return(Ok("Registered successfully"));
         }
         catch (Exception)
         {
             return(BadRequest("Enter the data"));
         }
     }
     else
     {
         return(BadRequest("Please enter the data"));
     }
 }
        public HttpResponseMessage Adduser(ConsumerTable consumer)
        {
            var username = (from c in db.ConsumerTables
                            where c.UserName == consumer.UserName
                            select c.UserName).ToList();

            if (username.Count > 0)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "This User Name is taken, Please Choose different username"));
            }
            else
            {
                var email = (from c in db.ConsumerTables
                             where c.Email == consumer.Email
                             select c.Email).ToList();
                if (email.Count > 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, "Userdata with given email already exists. Please choose different email or Login with current email"));
                }
                else
                {
                    var phone = (from c in db.ConsumerTables
                                 where c.PhoneNo == consumer.PhoneNo
                                 select c.PhoneNo).ToList();
                    if (phone.Count > 0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, "Userdata with given Phone Number already exists. Please Login"));
                    }
                    else
                    {
                        DateTime currentdate = System.DateTime.Now;
                        TimeSpan time        = currentdate.Subtract(consumer.DateofBirth);
                        if (time.Days < 3650)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, "You are Not eligible. The user should be 10 years old or above"));
                        }
                        byte[] encData_byte = new byte[consumer.Password.Length];
                        encData_byte = System.Text.Encoding.UTF8.GetBytes(consumer.Password);
                        string encodedpassword = Convert.ToBase64String(encData_byte);
                        consumer.Password = encodedpassword;

                        ConsumerTable ct = new ConsumerTable();
                        ct.UserName      = consumer.UserName;
                        ct.DateofBirth   = consumer.DateofBirth;
                        ct.Name          = consumer.Name;
                        ct.Email         = consumer.Email;
                        ct.PhoneNo       = consumer.PhoneNo;
                        ct.Password      = consumer.Password;
                        ct.Address       = consumer.Address;
                        ct.CardType      = consumer.CardType;
                        ct.SelectBank    = consumer.SelectBank;
                        ct.AccountNumber = consumer.AccountNumber;
                        ct.IFSC_Code     = consumer.IFSC_Code;
                        try
                        {
                            db.ConsumerTables.Add(ct);
                            db.SaveChanges();
                            db.adduserinadmin(consumer.UserName);
                            db.SaveChanges();
                            return(Request.CreateResponse(HttpStatusCode.OK, "Registered Successfully!!!"));
                        }
                        catch (Exception)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, "The mailid or the Name given is too large"));
                        }
                    }
                }
            }
        }