Esempio n. 1
0
        public IHttpActionResult Putuser(int id, user user)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != user.id)
            {
                return BadRequest();
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!userExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Esempio n. 2
0
        public IHttpActionResult Postuser(user user)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            string defaultPassword = WebConfigurationManager.AppSettings["defaultPassword"];

            TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");

            user.createdate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);
            user.password = Encrypt(defaultPassword);
            user.status = "1";

            db.users.Add(user);
            db.SaveChanges();

            if (user.id > 0) {

                string sendSingleSmsUrl = WebConfigurationManager.AppSettings["sendSingleSmsUrl"];
                string smsUserId = WebConfigurationManager.AppSettings["smsUserId"];
                string smsPassword = WebConfigurationManager.AppSettings["smsPassword"];
                string smsFrom = WebConfigurationManager.AppSettings["smsFrom"];
                string smsRegisterMsgTemplate = WebConfigurationManager.AppSettings["smsRegisterMsgTemplate"];

                smsRegisterMsgTemplate = String.Format(smsRegisterMsgTemplate, user.fullname.Replace(" ", "+"), user.mobile, defaultPassword);
                sendSingleSmsUrl = String.Format(sendSingleSmsUrl, smsUserId, smsPassword, smsFrom, user.mobile, smsRegisterMsgTemplate, "&");

                string output;

                using (WebClient client = new WebClient())
                {
                    output = client.DownloadString(sendSingleSmsUrl);
                }

                smsoutput smsoutput = new smsoutput();

                smsoutput.sentAction = "r";
                smsoutput.output = output;
                smsoutput.createDate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);
                smsoutput.actionid = user.id;

                db.smsoutputs.Add(smsoutput);
                db.SaveChanges();
            }

            return CreatedAtRoute("DefaultApi", new { id = user.id }, user);
        }