コード例 #1
0
        public async Task <int> InsertAsync(Postage postage)
        {
            using (var con = new SqlConnection(_configuration["ConnectionString"]))
            {
                var sqlCmd = @"INSERT INTO
                                Postagem (UsuarioId,
                                           Texto,
                                           Criacao)
                                VALUES (@usuarioId,
                                        @texto,
                                        @criacao); SELECT scope_identity();";

                using (var cmd = new SqlCommand(sqlCmd, con))
                {
                    cmd.CommandType = CommandType.Text;

                    cmd.Parameters.AddWithValue("usuarioId", postage.UserId);
                    cmd.Parameters.AddWithValue("texto", postage.Text);
                    cmd.Parameters.AddWithValue("criacao", postage.Created);

                    con.Open();
                    var id = await cmd
                             .ExecuteScalarAsync()
                             .ConfigureAwait(false);

                    return(int.Parse(id.ToString()));
                }
            }
        }
コード例 #2
0
 public ReturnType RemovePtAndPtM(string postage_id)
 {
     try
     {
         using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
         {
             /*List<Postage> list = alading.Postage.Where(p => p.PostageID == postageID).ToList();*/
             List <Postage>     postageList     = alading.Postage.Where(p => p.postage_id == postage_id).ToList();
             List <PostageMode> postageModeList = alading.PostageMode.Where(v => v.postage_id == postage_id).ToList();
             if (postageList.Count == 0 || postageModeList.Count == 0)
             {
                 return(ReturnType.NotExisted);
             }
             else
             {
                 Postage sy = postageList.First();
                 alading.DeleteObject(sy);
                 alading.DeleteObject(postageModeList);
                 alading.SaveChanges();
                 return(ReturnType.Success);
             }
         }
     }
     catch (SqlException sex)
     {
         return(ReturnType.ConnFailed);
     }
     catch (System.Exception ex)
     {
         return(ReturnType.OthersError);
     }
 }
コード例 #3
0
        public async Task <Postage> GetPostageByIdAsync(int postageId)
        {
            using (var con = new SqlConnection(_configuration["ConnectionString"]))
            {
                var sqlCmd = @$ "SELECT *
                                FROM 
	                                Postage
                                WHERE 
	                                Id= '{postageId}'"    ;

                using (var cmd = new SqlCommand(sqlCmd, con))
                {
                    cmd.CommandType = CommandType.Text;
                    con.Open();

                    var reader = await cmd
                                 .ExecuteReaderAsync()
                                 .ConfigureAwait(false);

                    while (reader.Read())
                    {
                        var postage = new Postage(int.Parse(reader["Id"].ToString()),
                                                  reader["Text"].ToString(),
                                                  reader["Photo"].ToString(),
                                                  reader["Video"].ToString(),
                                                  int.Parse(reader["ClientId"].ToString()),
                                                  DateTime.Parse(reader["Creation"].ToString()));
                        return(postage);
                    }

                    return(default);
コード例 #4
0
        public void EditWithPost_ShouldRedirectOnSuccessfulSave()
        {
            var postage = new Postage();

            postageController.Edit(postage)
            .ReturnsRedirectToRouteResult()
            .ToAction("Index");
        }
コード例 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            Postage postage = db.Postages.Find(id);

            db.Postages.Remove(postage);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
 private void LoadPostage(Postage postage)
 {
     if (postage != null)
     {
         int n = grvPostage.Rows.Add();
         grvPostage.Rows[n].Cells[0].Value = postage.KeyId;
     }
 }
コード例 #7
0
    	public void NewWithPost_ShouldAddNewPostage()
    	{
    		var postage = new Postage() { MaxWeight = 250, Price = new Money(5.25M), Name = "foo"};
    		postageController.New(postage)
    			.ReturnsRedirectToRouteResult()
    			.ToAction("Index");

			postageRepository.AssertWasCalled(x=>x.SaveOrUpdate(postage));
    	}
コード例 #8
0
 public ActionResult Edit([Bind(Include = "KeyId,DateApplied")] Postage postage)
 {
     if (ModelState.IsValid)
     {
         db.Entry(postage).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(postage));
 }
コード例 #9
0
 public Postage Add(Postage postage)
 {
     if (postage == null)
     {
         return(null);
     }
     db.Entry(postage).State = System.Data.Entity.EntityState.Added;
     db.SaveChanges();
     return(postage);
 }
コード例 #10
0
 public Postage Update(Postage postage)
 {
     if (postage == null)
     {
         return(null);
     }
     db.Entry(postage).State = EntityState.Modified;
     SaveChanges();
     return(postage);
 }
コード例 #11
0
ファイル: PostageDAO.cs プロジェクト: alandong3721/guage
        /// <summary>
        /// 获取邮费对象
        /// </summary>
        /// <param name="weight">包裹重量</param>
        /// <param name="departure">发件地址</param>
        /// <param name="destination">收件地址</param>
        /// <returns>邮费对象</returns>
        public Postage getPostage(float weight, string departure, string destination, string post_way)
        {
            Postage postage = new Postage();

            string sql = "select * from tb_rate where kg>=" + weight + " and departure='" + departure + "' and destination='" + destination + "' and post_way='" + post_way + "' order by kg asc";

            postage = getPostage(sql);

            return(postage);
        }
コード例 #12
0
        public ActionResult Create([Bind(Include = "KeyId,DateApplied")] Postage postage)
        {
            if (ModelState.IsValid)
            {
                db.Postages.Add(postage);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(postage));
        }
コード例 #13
0
        public void EditWithPost_ShouldRenderViewOnError()
        {
            postageController.ModelState.AddModelError("foo", "Bar");
            var postage = new Postage();

            postageController.Edit(postage)
            .ReturnsViewResult()
            .WithModel <ScaffoldViewData <Postage> >()
            .AssertNull(x => x.Message)
            .AssertAreSame(postage, x => x.Item);
        }
コード例 #14
0
 public bool SaveEntities(Postage postage)
 {
     if (postage.KeyId > 0)
     {
         if (postageDAL.Update(postage) != null)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #15
0
        public void Edit_ShouldShowEditViewWithExistingPostage()
        {
            var postageId = 3;
            var postage = new Postage { PostageId = postageId };

            postageRepository.Expect(pr => pr.GetById(postageId)).Return(postage);

            postageController.Edit(postageId)
                .ReturnsViewResult()
                .ForView("Edit")
                .WithModel<ScaffoldViewData<Postage>>()
                .AssertAreSame(postage, vd => vd.Item);
        }
コード例 #16
0
        public void NewWithPost_ShouldAddNewPostage()
        {
            var postage = new Postage()
            {
                MaxWeight = 250, Price = new Money(5.25M), Name = "foo"
            };

            postageController.New(postage)
            .ReturnsRedirectToRouteResult()
            .ToAction("Index");

            postageRepository.AssertWasCalled(x => x.SaveOrUpdate(postage));
        }
コード例 #17
0
        // GET: Postage/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Postage postage = db.Postages.Find(id);

            if (postage == null)
            {
                return(HttpNotFound());
            }
            return(View(postage));
        }
コード例 #18
0
 public bool SaveEntities(Postage postage, List <PostageDetail> postageDetail)
 {
     if (postage.KeyId == 0)
     {
         if (postageDAL.Add(postage) != null)
         {
             if (postageDetailBUS.SaveEntities(postageDetail))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #19
0
        public void Edit_ShouldShowEditViewWithExistingPostage()
        {
            var postageId = 3;
            var postage   = new Postage {
                Id = postageId
            };

            postageRepository.Expect(pr => pr.GetById(postageId)).Return(postage);

            postageController.Edit(postageId)
            .ReturnsViewResult()
            .ForView("Edit")
            .WithModel <ScaffoldViewData <Postage> >()
            .AssertAreSame(postage, vd => vd.Item);
        }
コード例 #20
0
        /// <summary>
        /// Store postage information from reader
        /// </summary>
        /// <param name="reader"></param>
        /// <returns>Postage model</returns>
        private Postage ReadSingleRow(SqlDataReader reader)
        {
            Postage postage = new Postage();

            postage.PostageID   = Convert.ToInt32($"{reader[0]}");
            postage.UserID      = Convert.ToInt32($"{reader[1]}");
            postage.ContactName = $"{reader[2]}";
            postage.State       = $"{reader[3]}";
            postage.City        = $"{reader[4]}";
            postage.State       = $"{reader[5]}";
            postage.Country     = $"{reader[6]}";
            postage.ZipCode     = $"{reader[7]}";
            postage.Phone       = $"{reader[8]}";
            return(postage);
        }
コード例 #21
0
        public async Task <Postage> InsertAsync(PostageInput input)
        {
            var userId = _logged.GetUserLoggedId();

            var postage = new Postage(input.Text, input.Foto, userId);

            //Validar classe com dados obrigatorios..

            var id = await _postageRepository
                     .InsertAsync(postage)
                     .ConfigureAwait(false);

            postage.SetId(id);

            return(postage);
        }
コード例 #22
0
        public ReturnType UpdatePostage(string postageCode, Postage postage)
        {
            try
            {
                using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
                {
                    /*var result = alading.Postage.Where(p => p.PostageID == postageID).ToList();*/
                    var result = alading.Postage.Where(p => p.postage_id == postageCode).ToList();
                    if (result.Count == 0)
                    {
                        return(ReturnType.NotExisted);
                    }

                    Postage ob = result.First();
                    //ob.name = postage.name;
                    ob.memo             = postage.memo;
                    ob.created          = postage.created;
                    ob.modified         = postage.modified;
                    ob.post_price       = postage.post_price;
                    ob.post_increase    = postage.post_increase;
                    ob.express_price    = postage.express_price;
                    ob.express_increase = postage.express_increase;
                    ob.ems_price        = postage.ems_price;
                    ob.ems_increase     = postage.ems_increase;
                    ob.postage_modes    = postage.postage_modes;

                    if (alading.SaveChanges() == 1)
                    {
                        return(ReturnType.Success);
                    }
                    else
                    {
                        return(ReturnType.OthersError);
                    }
                }
            }
            catch (SqlException sex)
            {
                return(ReturnType.ConnFailed);
            }
            catch (System.Exception ex)
            {
                return(ReturnType.OthersError);
            }
        }
コード例 #23
0
ファイル: PostageDAO.cs プロジェクト: alandong3721/guage
        /// <summary>
        /// 通过sql在数据库中获取计算所要用到的 计算率 语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        private Postage getPostage(string sql)
        {
            Postage postage = new Postage();

            DataTable table = new DBOperateCommon().excuteQuery(sql);

            if (table.Rows.Count > 0)
            {
                postage.Rate        = Convert.ToSingle(table.Rows[0]["rate"].ToString());
                postage.Weight      = Convert.ToSingle(table.Rows[0]["kg"].ToString());
                postage.Departure   = table.Rows[0]["departure"].ToString();
                postage.Destination = table.Rows[0]["destination"].ToString();
                postage.Pickup_fees = Convert.ToSingle(table.Rows[0]["pickup_fees"].ToString());
                postage.Per         = Convert.ToInt32(table.Rows[0]["per"].ToString());
            }

            return(postage);
        }
コード例 #24
0
        private void btnAddPostage_Click(object sender, EventArgs e)
        {
            if (postageBUS.CheckAddPostageDetails(HourMarks))
            {
                Postage postage = new Postage();
                postage.KeyId       = 0;
                postage.DateApplied = DateTime.Now;

                if (postageBUS.SaveEntities(postage, HourMarks))
                {
                    MessageBox.Show("Thêm thành công");

                    HourMarks.Clear();
                    shared.ClearDataGridView(grvAddHourMark);
                    LoadAll();
                }
            }
        }
コード例 #25
0
 public ReturnType AddPostage(Postage postage)
 {
     try
     {
         using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString()))
         {
             Postage oldPostage = alading.Postage.FirstOrDefault(p => p.postage_id == postage.postage_id);
             if (oldPostage == null)
             {
                 alading.AddToPostage(postage);
             }
             else
             {
                 oldPostage.name             = postage.name;
                 oldPostage.memo             = postage.memo;
                 oldPostage.post_price       = postage.post_price;
                 oldPostage.post_increase    = postage.post_increase;
                 oldPostage.express_price    = postage.express_price;
                 oldPostage.express_increase = postage.express_increase;
                 oldPostage.ems_price        = postage.ems_price;
                 oldPostage.ems_increase     = postage.ems_increase;
                 oldPostage.modified         = postage.modified;
                 oldPostage.postage_modes    = postage.postage_modes;
                 oldPostage.created          = postage.created;
             }
             if (alading.SaveChanges() == 1)
             {
                 return(ReturnType.Success);
             }
             else
             {
                 return(ReturnType.PropertyExisted);
             }
         }
     }
     catch (SqlException sex)
     {
         return(ReturnType.ConnFailed);
     }
     catch (Exception ex)
     {
         return(ReturnType.OthersError);
     }
 }
コード例 #26
0
ファイル: PostageRepository.cs プロジェクト: LayaneB/Backend
        public async Task <List <Postage> > GetPostageByClientIdAsync(int clientId)
        {
            using (var con = new SqlConnection(_configuration["ConnectionString"]))
            {
                var sqlCmd = @$ "SELECT       Id,
                                     Text,
                                     Photo,
                                     Video,
                                     ClientId,
                                     Creation
                                FROM 
	                                Postage
                                WHERE 
	                                ClientId= '{clientId}'"    ;

                using (var cmd = new SqlCommand(sqlCmd, con))
                {
                    cmd.CommandType = CommandType.Text;
                    con.Open();

                    var reader = await cmd
                                 .ExecuteReaderAsync()
                                 .ConfigureAwait(false);

                    var postagesForClient = new List <Postage>();

                    while (reader.Read())
                    {
                        var postage = new Postage(int.Parse(reader["Id"].ToString()),
                                                  reader["Text"].ToString(),
                                                  reader["Photo"].ToString(),
                                                  reader["Video"].ToString(),
                                                  int.Parse(reader["ClientId"].ToString()),
                                                  DateTime.Parse(reader["Creation"].ToString()));

                        postagesForClient.Add(postage);
                    }

                    return(postagesForClient);
                }
            }
        }
コード例 #27
0
ファイル: PostageAppService.cs プロジェクト: LayaneB/Backend
        public async Task <Postage> InsertAsync(PostageInput input)
        {
            var clientId = _logged.GetClientLoggedId();

            var postage = new Postage(input.Text,
                                      input.Photo,
                                      input.Video,
                                      clientId,
                                      DateTime.Now);

            //Validar classe com dados obrigatorios..

            var id = await _postageRepository
                     .InsertAsync(postage)
                     .ConfigureAwait(false);

            postage.SetId(id);

            return(postage);
        }
コード例 #28
0
        public async Task <List <Postage> > GetPostageFriendAsync(int userId)
        {
            using (var con = new SqlConnection(_configuration["ConnectionString"]))
            {
                var sqlCmd = @$ "SELECT  a.UsuarioId, a.UsuarioAmigoId, 
                                        p.Id,
                                        p.Foto,
                                        p.Texto,
                                        p.Criacao
                                        FROM 
                                        Postagem p
										INNER JOIN Amigos a
										on p.UsuarioId=a.UsuarioAmigoId
                                        where a.UsuarioId='{userId}' 
                                        order by  p.Criacao desc;";

                using (var cmd = new SqlCommand(sqlCmd, con))
                {
                    cmd.CommandType = CommandType.Text;
                    con.Open();

                    var reader = await cmd
                                 .ExecuteReaderAsync()
                                 .ConfigureAwait(false);

                    var postagesForUser = new List <Postage>();

                    while (reader.Read())
                    {
                        var postage = new Postage(int.Parse(reader["Id"].ToString()),
                                                  reader["Texto"].ToString(),
                                                  reader["Foto"].ToString(),
                                                  int.Parse(reader["UsuarioId"].ToString()),
                                                  DateTime.Parse(reader["Criacao"].ToString()));

                        postagesForUser.Add(postage);
                    }

                    return(postagesForUser);
                }
            }
コード例 #29
0
        /// <summary>
        /// 计算从英国寄往台湾的包裹费用
        /// </summary>
        /// <param name="weight">重量</param>
        /// <param name="length">长度</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <returns></returns>
        private float parcelforceAutoFromUKToTaiWan(float weight, float length, float width, float height)
        {
            Postage rate  = new Postage();
            float   price = 0;

            //获得包裹的实际重量,如果体积过大就计算体积重
            weight = (float)Math.Max(weight, ((length * width * height) / 5000.0));

            if (weight <= 30.0)
            {
                rate  = new PostageDAO().getPostage(weight, "UK", "TaiWan", "Parcelforce priority auto");
                price = rate.Rate;
            }
            else
            {
                rate  = new PostageDAO().getPostage(30.0f, "UK", "TaiWan", "Parcelforce priority auto");
                price = (float)(rate.Rate + (weight - 30.0) * 1.78 * 2 * 1.01);
            }

            return(price);
        }
コード例 #30
0
        public async Task <Postage> InsertAsync(PostageInput input)
        {
            var userId = _logged.GetUserLoggedId();

            var postage = new Postage(input.Text, userId, input.Photo);

            if (postage.Text == null || postage.Text == "")
            {
                throw new ArgumentException("Existem dados que são obrigatórios e não foram preenchidos");
            }



            var id = await _postageRepository
                     .InsertAsync(postage)
                     .ConfigureAwait(false);

            postage.SetId(id);

            return(postage);
        }
コード例 #31
0
        public async Task <List <Postage> > GetPostageByUserIdAsync(int userId)
        {
            using (var con = new SqlConnection(_configuration["ConnectionString"]))
            {
                var sqlCmd = @$ "SELECT Id,
	                                   UsuarioId,
                                       Texto,
                                        Foto,
                                       Criacao
                                FROM 
	                                Postagem
                                WHERE 
	                                UsuarioId= '{userId}'"    ;

                using (var cmd = new SqlCommand(sqlCmd, con))
                {
                    cmd.CommandType = CommandType.Text;
                    con.Open();

                    var reader = await cmd
                                 .ExecuteReaderAsync()
                                 .ConfigureAwait(false);

                    var postagesForUser = new List <Postage>();

                    while (reader.Read())
                    {
                        var postage = new Postage(int.Parse(reader["Id"].ToString()),
                                                  reader["Texto"].ToString(),
                                                  reader["Foto"].ToString(),
                                                  int.Parse(reader["UsuarioId"].ToString()),
                                                  DateTime.Parse(reader["Criacao"].ToString()));

                        postagesForUser.Add(postage);
                    }

                    return(postagesForUser);
                }
            }
        }
コード例 #32
0
        /// <summary>
        /// 计算从英国寄到台湾的邮费
        /// </summary>
        /// <param name="weight">重量</param>
        /// <param name="length">长度</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <returns></returns>
        private float parcelforceEconomyFromUKToTaiWan(float weight, float length, float width, float height)
        {
            float price = 0;

            Postage postage = new Postage();

            //获得包裹的实际重量,如果体积过大就计算体积重
            weight = (float)Math.Max(weight, ((length * width * height) / 5000.0));

            if (weight <= 30.0)
            {
                postage = new PostageDAO().getPostage(weight, "UK", "TaiWan", "Parcelforce economy");
                price   = postage.Rate;
            }
            else
            {
                postage = new PostageDAO().getPostage(30.0f, "UK", "TaiWan", "Parcelforce economy");
                price   = (float)(postage.Rate + (weight - 30.0) * 1.75 * 2 * 1.01);
            }

            return(price);
        }
コード例 #33
0
 public ShopViewData WithPostage(Postage postage)
 {
     this.Postage = postage;
     return this;
 }
コード例 #34
0
    	public void EditWithPost_ShouldRedirectOnSuccessfulSave()
    	{
    		var postage = new Postage();
    		postageController.Edit(postage)
    			.ReturnsRedirectToRouteResult()
				.ToAction("Index");
    	}
コード例 #35
0
 	public void EditWithPost_ShouldRenderViewOnError()
 	{
 		postageController.ModelState.AddModelError("foo", "Bar");
 		var postage = new Postage();
 		postageController.Edit(postage)
 			.ReturnsViewResult()
 			.WithModel<ScaffoldViewData<Postage>>()
 			.AssertNull(x => x.Message)
 			.AssertAreSame(postage, x => x.Item);
 	}
コード例 #36
0
    	public void NewWithPost_ShouldAddNewPostage()
    	{
    		var postage = new Postage() { MaxWeight = 250, Price = (decimal)5.25, Name = "foo"};
    		postageController.New(postage)
    			.ReturnsRedirectToRouteResult()
    			.ToAction("Index");

			postageRepository.AssertWasCalled(x=>x.InsertOnSubmit(postage));
    	}