public ActionResult Create(Pharmci pharmci)
        {
            if (ModelState.IsValid)
            {
                pharmci.Id = Guid.NewGuid();
                db.Pharmcis.Add(pharmci);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(pharmci);
        }
 public HttpResponseMessage Post(MyRegisterModel model)
 {
     var oldDonor = db.GetByUserName(model.UserName);
        if (oldDonor != null)
        {
        var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
        {
            Content = new StringContent("Email already exists"),
            ReasonPhrase = "Email already exists"
        };
        return resp; //throw new HttpResponseException(resp);
        }
        var donor = new Pharmci()
        {
        Id = Guid.NewGuid(),
        UserName = model.UserName,
        DisplayName = model.DisplayName,
        Phone = model.Phone,
        BloodType = model.BloodType,
        ZoneName = model.Zone,
        };
        donor.SetPassword(model.Password);
        try
        {
        db.CreateUser(donor);
        return new HttpResponseMessage()
        {
            Content = new StringContent("Success")
        };
        }
        catch (Exception exc)
        {
        var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
        {
            Content = new StringContent("Failed to register a new user:"******"Failed to register a new user"
        };
        return resp;  //throw new HttpResponseException(resp);
        }
 }
示例#3
0
        private OAuthResponse CreateAccessToken(Pharmci donor)
        {
            var token = new DemoToken(donor.UserName, donor.Id);
            Tokens.Add(token);

            return new OAuthResponse
            {
                DonorId = donor.Id,
                BloodType = donor.BloodType,
                IsFirstTimeDonor =  donor.IsFirstTimeDonor,
                LastDonationDate = donor.LastDonationDate,
                AccessToken = token.AccessToken,
                Expires = token.ExpireSeconds,
                RefreshToken = token.RefreshToken,
                RequireSsl = false,
                Success = true
            };
        }
示例#4
0
        public void CreateUser(Pharmci donor)
        {
            if (GetByUserName(donor.UserName) != null)
            throw new Exception("A user with same username already exists");

            // Set Creation Date
            donor.RegistrationDate = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm", System.Globalization.CultureInfo.InvariantCulture);
            donor.DateOfBirth = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm", System.Globalization.CultureInfo.InvariantCulture);
            donor.LastDonationDate = System.DateTime.Now.ToString("yyyy/MM/dd HH:mm", System.Globalization.CultureInfo.InvariantCulture);
            donor.IsFirstTimeDonor = true;

            db.Pharmcis.Add(donor);

            try
            {
            db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {

            }
        }
 public ActionResult Edit(Pharmci pharmci)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pharmci).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(pharmci);
 }