public List<MacActionSerial> GetAll() { List<MacActionSerial> items = new List<MacActionSerial>(); using (StoredProcedure sp = new StoredProcedure("MacActionSerial_GetAll")) { var r = sp.ExecuteReader(); if (r != null) { while (r.Read()) { MacActionSerial item = new MacActionSerial { BuyDate = Convert.ToDateTime(r["BuyDate"]), Email = Convert.ToString(r["Email"]), Seller = Convert.ToInt32(r["Seller"]), ID = Convert.ToInt32(r["ID"]), Serial = Convert.ToString(r["Serial"]), SellerName = Convert.ToString(r["SellerName"]), Status = Convert.ToInt32(r["Status"]) }; items.Add(item); } } } return items; }
public virtual int Add(MacActionSerial item) { int newID = 0; using (StoredProcedure sp = new StoredProcedure("MacActionSerial_AddItem")) { sp.Params.Add("@BuyDate", System.Data.SqlDbType.DateTime).Value = item.BuyDate; sp.Params.Add("@Email", System.Data.SqlDbType.NVarChar).Value = item.Email; sp.Params.Add("@Serial", System.Data.SqlDbType.NVarChar).Value = item.Serial; sp.Params.Add("@Seller", System.Data.SqlDbType.Int).Value = item.Seller; newID = Convert.ToInt32(sp.ExecuteScalar()); } return newID; }
public virtual void Delete(MacActionSerial item) { int newID = 0; using (StoredProcedure sp = new StoredProcedure("MacActionSerial_DeleteItem")) { sp.Params.Add("@ID", System.Data.SqlDbType.Int).Value = item.ID; try { sp.ExecuteNonQuery(); } catch (Exception ex) { Debug.WriteLine("MacActionSerial_DeleteItem:" + ex.ToString()); } } }
public virtual int Update(MacActionSerial item) { int newID = 0; using (StoredProcedure sp = new StoredProcedure("MacActionSerial_UpdateItem")) { Debug.WriteLine(string.Format("id={0}, status={1}", item.ID, item.Status)); sp.Params.Add("@Status", System.Data.SqlDbType.Int).Value = item.Status; sp.Params.Add("@ID", System.Data.SqlDbType.Int).Value = item.ID; sp.Params.Add("@Email", System.Data.SqlDbType.NVarChar).Value = item.Email; sp.Params.Add("@Serial", System.Data.SqlDbType.NVarChar).Value = item.Serial; try { sp.ExecuteNonQuery(); } catch (Exception ex) { Debug.WriteLine("MacActionSerial_UpdateItem:" + ex.ToString()); } } return newID; }
private void SendMail(MacActionSerial item) { MailDefinition md = new MailDefinition(); md.BodyFileName = "~/MailTemplates/request_MacAction.htm"; Dictionary<string, string> d = new Dictionary<string, string>(); d.Add("<%Serial%>", item.Serial); d.Add("<%BuyDate%>", item.BuyDate.ToShortDateString()); d.Add("<%Email%>", item.Email); d.Add("<%Seller%>", item.SellerName); md.IsBodyHtml = true; ContactFormsCache forms = new ContactFormsCache(); string formName = string.Format("Request_{0}", Apple.Web.Controls.RequestStatusForm.StatusType.MacAction); ContactForm form = forms.GetByName(formName); if (form == null) throw new InvalidOperationException(string.Format("Can not find settings for form {0}", formName)); string subject = form.Subject; string to = form.To; string cc = form.CC; md.Subject = subject; if (!string.IsNullOrEmpty(cc)) { md.CC = cc; } MailMessage message = md.CreateMailMessage(to, d, this); SmtpClient sc = new SmtpClient(); sc.Send(message); }
private CheckCheckSerialNumberResponse DoCheckSerialNumber() { CheckCheckSerialNumberResponse response = new CheckCheckSerialNumberResponse(); SerialNumberRepository snRepository = new SerialNumberRepository(); string number = string.Empty; if (Request["SNValue"] != null) number = Request["SNValue"].ToString().ToUpperInvariant(); string BuyDate = string.Empty; if (Request["BuyDate"] != null) BuyDate = Request["BuyDate"].ToString(); string Email = string.Empty; if (Request["Email"] != null) Email = Request["Email"].ToString(); int seller = 0; try { if (Request["Seller"] != null) seller = int.Parse(Request["Seller"].ToString()); } catch (Exception) { response.IsValid = false; response.Message = "invalid seller"; return response; } if (string.IsNullOrEmpty(Email.Trim())) { response.IsValid = false; response.Message = "invalid email"; return response; } if (seller == 0) { response.IsValid = false; response.Message = "invalid seller"; return response; } List<string> list = (new MacActionSerials()).GetSerialNumbers(); if (list.Contains(number)) { response.IsValid = false; response.Message = "duplicate number"; return response; } DateTime buydate = DateTime.MinValue; if(!DateTime.TryParseExact(BuyDate, "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out buydate)) { response.Message = "invalid date"; response.IsValid = false; return response; } if (buydate < new DateTime(2013, 02, 8) || buydate > new DateTime(2013, 3, 10)) { response.IsValid = false; response.Message = "invalid daterange"; return response; } ResolveCity(); MacActionSerials rep = new MacActionSerials(); var item = new MacActionSerial { Serial = number, BuyDate = buydate, Email = Email, Seller = seller, SellerName= Sellers.FirstOrDefault(s=>s.ID==seller).Name }; try { item.ID = rep.Add(item); SendMail(item); SendEmail(item.ID, item.Status, item.Email, item.Serial); } catch (Exception ex) { Debug.WriteLine("MacAction: " + ex.ToString()); } return response; }